Task #3419
closedReplace include guards with #pragma once
0%
Description
Although non-standard, #pragma once
is widely supported by C/C++ compilers on several platforms. Moreover, it has several advantages over classic include guards:
- it's shorter to type
- less error-prone (typos...)
- no need to come up with a unique (and long) macro name
- nothing to change when the header is renamed or moved
Updated by Junxiao Shi about 8 years ago
- Project changed from NFD to ndn-cxx
- Category changed from Build to Docs
This shall belong to ndn-cxx Docs because the requirement comes from code-style.
I disagree with this because compiler is allowed to halt and catch fire when seeing #pragma
.
Updated by Davide Pesavento about 8 years ago
Junxiao Shi wrote:
I disagree with this because compiler is allowed to halt and catch fire when seeing
#pragma
.
Which in technical terms means..?
Updated by Alex Afanasyev about 8 years ago
I'm not in favor of the change.
Even though it is shorter and more concise, there is still a tiny risk of the pragma not supported (= more my personal preference). I also not sure what is implication of pragma once
with conjunction of precompiled headers.
Updated by Davide Pesavento about 8 years ago
I seriously doubt you'll find a compiler that supports C++11 but doesn't support #pragma once
...
Anyway, I won't insist, since you both seem against it.
Updated by Michael Sweatt about 8 years ago
I also vote no. Depending on a non-standard feature for convenience is not worth it.
Updated by Junxiao Shi about 8 years ago
- Status changed from New to Rejected
Reply to note-2:
#pragma
is undefined behavior, as I read from some book.
HCF, launching missiles, or getting watermelon-sized hail are all acceptable.
Updated by Davide Pesavento about 8 years ago
Junxiao Shi wrote:
#pragma
is undefined behavior, as I read from some book.
HCF, launching missiles, or getting watermelon-sized hail are all acceptable.
That's incorrect. The behavior of #pragma
is precisely defined by the standard when followed by STDC
, and it's implementation-defined when not followed by STDC
. See n1256 ยง6.10.6.
"Implementation-defined" means that each compiler implementation is allowed to behave however they choose, but also "Each implementation shall include documentation describing its characteristics and behavior in these respects", so the behavior is compiler-specific, but you can rely on it for that particular compiler. This is very different from "undefined behavior".