Quantcast
Channel: Can #endif in an included file be used to close a #if in the including file? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Can #endif in an included file be used to close a #if in the including file?

$
0
0

Let's say I have two files, a.h:

#if 1
#include "b.h"

and b.h:

#endif

Both gcc's and clang's preprocessors reject a.h:

$ cpp -ansi -pedantic a.h >/dev/null
In file included from a.h:2:0:
b.h:1:2: error: #endif without #if
 #endif
  ^
a.h:1:0: error: unterminated #if
 #if 1
 ^

However, the C standard (N1570 6.10.2.3) says:

A preprocessing directive of the form

# include "q-char-sequence" new-line

causes the replacement of that directive by the entire contents of the source file identified by the specified sequence between the " delimiters.

which appears to permit the construct above.

Are gcc and clang not compliant in rejecting my code?


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images