Include guards in header files are often used to protect sections of code from double inclusion:
#ifndef FOOBAR_H
#define FOOBAR_H
extern void myfoofunc(void);
#endif
Include guards typically rely on the expectation that if an object-like macro was already defined, the lines within the #ifndef
block will not included -- thus avoiding double inclusion.
I've noticed that the #define
line for many include headers have empty replacement-lists. Does the C99 standard guarantee that object-like macros defined with an empty replacement-list will be considered "defined" by #ifndef
?
When describing the syntax of #define
, the C99 standard seems to imply that a replacement-list is required in section 6.10.3 paragraph 9:
A preprocessing directive of the form
# define identifier replacement-list new-line
defines an object-like macro that causes each subsequent instance of the macro name to be replaced by the replacement list of preprocessing tokens that constitute the remainder of the directive. The replacement list is then rescanned for more macro names as specified below.
Does this mean include headers should instead be of the form: #define FOOBAR_H 1
?