Newsgroups: comp.lang.c
Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps
From: flaps@dgp.toronto.edu (Alan J Rosenthal)
Subject: Re: Pragmas
Message-ID: <1988Jan8.015032.8598@jarvis.csri.toronto.edu>
Organization: University of Toronto
References: <8801021358.AA15890@decwrl.dec.com> <504@cresswell.quintus.UUCP> <1988Jan3.162343.1697@jarvis.csri.toronto.edu> <506@cresswell.quintus.UUCP>
Date: Fri, 8-Jan-88 01:50:32 EST


Let's be careful not to turn this into a flame war, please, but in a recent
article ok@quintus.UUCP (Richard A. O'Keefe) writes:

>Passing #pragmas through to the compiler means that
>(1) /lib/cpp	has to parse stuff which is significant to the C
>		compiler, and ONLY to the C compiler.

Not 'parse', just 'accept lines beginning with'.  cpp already must
include code for taking the first token of a '#' line to see if it is
'if', 'include', etc.  All it has to do is
    if(strcmp(token,"pragma") == 0)
	printf("%s\n",line);

...

>#line is a different case...
>In fact, as your example shows, the main function of # <lino> <file>
>is not to be passed through by the preprocessor, but to be generated
>by the preprocessor.  I have never written a # <lino> <file> in my
>life, but the preprocessor has made millions for me ...

Ahem, no human writes # <line> <file> lines, but plenty of programs
which come before cpp do, such as yacc and lex.  (In fact, this is the
K&R documented use for this feature.)

...

>One of the things one wants to do with a program is to analyse it...

>The easiest way to hack this is
>	cc -E source.c | analyser
>which means that your analyser doesn't have to be a preprocessor as
>well as a parser!  The # <line> <file> lines generated by the
>preprocessor tell you ... where things came from...
>
>If the "pragma" construct is defined as pragma(..) in the compiler
>language, then each tool has to be prepared to skip a parenthesis
>balanced sequence of tokens after pragma() but can otherwise ignore
>the construct.  But if #pragma is a pass-through (as some quite
>undocumented form) then I can't defend my tool against it, because
>I don't know what the passed-through form is going to look like.

But even better, if you write your cpp to take an option which causes
it to eat pragmas, or to object to them, either of which (or both)
would be easy to implement, it's even easier.  The ANSI committee can't
specify this any more than they can specify the existence of cpp or
cc -E, but I would hope that good cpp writers would implement it.

In any case, your "as some quite undocumented form" misses the point.
The documentation of this form is part of the documentation for the
(not necessarily existing) cpp, not for the C standard.

ajr
-- 
"Bill Joy uses EMACS."  - D. Hugh Redelmeier
