1

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?

Sam
  • 7,252
  • 16
  • 46
  • 65
Ragas
  • 130
  • 2
  • 11

1 Answers1

1

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.

  • Sadly I don't remember where I saw that, it was probably some library for mathematical functions. It was under linux though. – Ragas Mar 11 '15 at 13:02