"Neil" <ne**@daikokuya.co.uk> writes:
Ben Pfaff wrote: "tedu" <tu@zeitbombe.org> writes:
> having read the section on preprocessing (6.10) and not finding the
> answer, is the following code acceptable? i have compilers which
> accept it, accept it with a warning, and refuse to compile it. i'm
> wondering which is correct.
>
> #if 0
> print FILEPTR "int main()
>
> #endif
It is incorrect. Groups that are skipped must consist of valid
preprocessing tokens.
No, it is fine. The group consists of valid preprocessing tokens, one
of which is ". These preprocessing tokens must be ignored as the
standard dictates.
A compiler must accept it.
No, it's undefined behavior. (We've had a claim that it's illegal,
and one that it's legal; I figured we should cover all the
possibilities.)
C99 6.4p3:
A _token_ is the minimal lexical element of the language in
translation phases 7 and 8. The categories of tokens are:
keywords, identifiers, constants, string literals, and
punctuators. A preprocessing token is the minimal lexical element
of the language in translation phases 3 through 6. The categories
of preprocessing tokens are: header names, identifiers,
preprocessing numbers, character constants, string literals,
punctuators, and single non-white-space characters that do not
lexically match the other preprocessing token categories. If a '
or a " character matches the last category, the behavior is
undefined.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.