Project

General

Profile

Actions

Task #3419

closed

Replace include guards with #pragma once

Added by Davide Pesavento about 8 years ago. Updated about 8 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Category:
Docs
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:

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
Actions #1

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.

Actions #2

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..?

Actions #3

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.

Actions #4

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.

Actions #5

Updated by Michael Sweatt about 8 years ago

I also vote no. Depending on a non-standard feature for convenience is not worth it.

Actions #6

Updated by Davide Pesavento about 8 years ago

So... reject?

Actions #7

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.

Actions #8

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".

Actions

Also available in: Atom PDF