Talk:cpp/preprocessor

Preprocessing directives / "non-directives" ?
Hi, I'd like to describe the PP further detailed, but stumbled across some sentences in the standard talking about "non-directives". To be precise, I'm refering to document http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3337.pdf, section 16, pages 387 and 388. To me that means:
 * A "preprocessing-file" consists of zero or more "group-part"s, each of these is either an "if-section", or a "control-line", or a "text-line", or a '#' followed by a "non-directive". A "non-directive" consists of one or more "preprocessing-token"s followed by the new line character.

It also says that "a non-directive shall not begin with any of the directive names appearing in the syntax". I read through the rest of section 16, and couldn't find the semantics of such "non-directive"s - it seems like the standard just says what it looks like, but not what it does and what it is for. Basicly my question is: how shall a standard conformant compiler behave, if a line
 * #blub blub blub

is in the input file? --87.153.239.249 14:01, 13 January 2013 (PST)


 * Good question. It looks like non-directive came from C99. I believe the intent is to make any line starting with a '#' a preprocessor directive -- even if what follows is not one of the accepted preprocessor tokens like 'ifdef' or 'define'. This tells compilers that they should treat it as part of the preprocessor stuff.  It also allows compilers to add their own custom preprocessor behavior, since the standard doesn't define what should happen in that case. See http://stackoverflow.com/questions/5679202/c99-despite-the-name-a-non-directive-is-a-preprocessing-directive and http://compgroups.net/comp.std.c/what-is-the-purpose-of-a-non-directive/434092 for some discussion. --Nate 08:23, 14 January 2013 (PST)


 * Thanks! Looks like I'm not the first one stumbling across this, and that some websearch would have given me a better answer than the standard itself. In this respect I'm a little disappointed by the standard: I expected it to be a standalone document, and that it at very least said whether its implementation defined, or undefined behaviour.
 * I think it's worth a footnote in this wiki. --87.148.221.8 15:32, 17 January 2013 (PST)