On Fri, Sep 24, 2021 at 08:16:22PM +0100, ropers wrote: > I'm looking at the #include guards in various .h files in /usr/include. > There seem to be different (comment) idioms present at the bottom of > those files/#include guards. > > > For example: > > ctype.h: > #endif /* !_CTYPE_H_ */ > > float.h: > #endif /* _FLOAT_H_ */ > > err.h: > #endif /* !_ERR_H_ */ > > curses.h: > #endif /* _CURSES_H_ */ > > > Is there agreement on what notation is correct? > > > It seems to me that both are defensible or at least arguable. The > straightforward idiom without the ! works simply as a reminder of > which file/#define the #endif belongs to. The version with the ! > seems to me to be intended to also take note of the fact that it says > #ifndef at the top, with emphasis on the n. > > From running commands such as > $ grep '#endif /\* _' *.h | wc -l > and > $ grep '#endif /\* !_' *.h | wc -l > it would appear the former is about twice as common. > > > Should a single style be adopted? > > > style(9) doesn't cover this admittedly less-than-crucial point. > Speaking of include guards, is #pragma once ever okay here, or is that > a big no-no? > > Thanks and regards, > Ian > > (Ian Ropers) > Personally, I would prefer the style without the "!" because I think the bang makes it look more important than it is. #pragma once is non-standard and #ifndef works fine, so I see no reason to use it.
craekz
