Hacker News new | ask | show | jobs
by nitrogen 5301 days ago
The more modern gcc handling is with "#pragma once":

I've considered switching to this, but in the interest of maximum hypothetical portability, I've decided to stick with the #ifndef include guard. I've just checked the C1X standard draft I have, and #pragma once is still not in the standard (6.10.6.1 in the version I have).

As for your other points, I agree with the notion that a header file should include its dependencies, but no more. I suppose my thinking on this is influenced by the dependency tracking of Linux package managers such as apt.

1 comments

We use both internally, actually. GNU gcc/g++ and IBM xlc/xlC all support doing this:

  #if defined(... all the compilers above ...)
  # define PRAGMA_ONCE _Pragma("once")
  #else
  # define PRAGMA_ONCE
  #endif
Specifically, MSVC and HP cc/aCC do not support it. Oracle cc/CC does the #ifndef/#define detection and internally does something similar to what the pragma enables in other compilers.