Ragas
Ragas

Reputation: 130

Why do some include guards have a defined value?

Usually when using include guards I write them like so:

#ifndef FILENAME_H
#define FILENAME_H

...

#endif // FILENAME_H

Now in some librarys I've seen something like:

#ifndef FILENAME_H
#define FILENAME_H 1

...

#endif // FILENAME_H

After some reserach I didn't find any reason as to why the include-gurad would be needed to be initialized.

Is there any reason for doing this?

Upvotes: 1

Views: 121

Answers (1)

Tim Handschack
Tim Handschack

Reputation: 48

Though I've never seen such a compiler, I've been told an "empty" define could be regarded as not defined. I'm very interested in which compiler behaves like so.

Even C89 states: 3.8.1 Conditional inclusion Constraints

The expression that controls conditional inclusion shall be an integral constant expression [...] of the form

defined identifier

defined ( identifier )

which evaluate to 1 if the identifier is currently defined as a macro name (that is, if it is predefined or if it has been the subject of a #define preprocessing directive without an intervening #undef directive with the same subject identifier), 0 if it is not.

Upvotes: 1

Related Questions