Closed Bug 881577 Opened 11 years ago Closed 11 years ago

Use the canonical #ifndef wrapper form in SpiderMonkey headers so that GCC and clang can avoid including them more than once per compilation unit.

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 881579

People

(Reporter: n.nethercote, Assigned: n.nethercote)

Details

If you have a canonical #ifndef wrapper in a header file, e.g.:

  #ifndef FOO_H__
  ...
  #endif

clang and GCC will avoid re-including the header if FOO_H__ is defined.  But
for this to work the #ifndef wrapper must have the above form (|#if
defined(FOO_H__)| is also allowed, and there can't be any tokens before or
afterwards (but whitespace and comments are ok).  

(See
http://gcc.gnu.org/onlinedocs/cpp/Once_002dOnly-Headers.html#Once_002dOnly-Headers
and http://gcc.gnu.org/onlinedocs/cppinternals/Guard-Macros.html for details.)

SpiderMonkey has numerous header files that violate this, and so get
multiply-included unnecessarily.
Driveby comment, but if we're going to do this (I'm certainly not opposed!), we should use include guards don't violate C++ naming rules.  Most particularly they shouldn't start with "_", and they shouldn't include sequential underscores.  A whole bunch of our existing include guards violate these rules right now, because copypasta for one, and because who ever has time to clean up that sort of junk?

It might also be worth standardizing include-guard naming at the same time.  I have no feelings on the format, except that it seems worth poking the Gecko people to pick one scheme that everyone, everywhere, could use.
Dup'ing;  this got double-filed due to a bzexport snafu on my end.
Status: NEW → RESOLVED
Closed: 11 years ago
Resolution: --- → DUPLICATE
You need to log in before you can comment on or make changes to this bug.