Bug (?) in C preprocessor

stephenf at elecvax.UUCP stephenf at elecvax.UUCP
Wed May 30 05:10:07 AEST 1984


>   From: boyd at basser.SUN (Boyd Roberts)
>   References: <204 at elecvax.SUN>
>   Organization: Dept of C.S., University of Sydney
>   
>   No.  The reference manual states:
>   
>   	"Each occurrance of an identifier mentioned in the
>   	formal parameter list of the definition is replaced
>   	by the corresponding token string from the call."

It also state that subsequent occurrences of identifiers used in
ordinary "#define"s are replaced by the appropriate token-string
wherever they occur. What the manual doesn't specify is any order
for replacement.
    
>    	"...the replacement string is rescanned for more
>    	defined identifiers."

Exactly, but which ones come first?
    
>    	"Text inside a string or character constant is not
>    	subject to replacement."

The identifier is not inside a string or character constant. It happens
to be inside another macro, which may introduce quotes at that point,
when replacement occurs. But not until replacement occurrs.
    
>    Hence:
>    
>    #define quote(x)	"x"
>    #define gooeys		sooterkin
>    
>    quote(gooeys) expands to "gooeys" and not "sooterkin".

Your "hence" does not follow at all.
	quote(gooeys)
may first be expanded to
	quote(sooterkin)
and thence to "sooterkin" in complete accordance with the reference
manual. It's not defined.
    
>    I wouldn't advise a change to the preproccessor to do this alternate
>    expansion because by definition it would NOT be the C preproccessor.

By definition where? Not the C reference manual.
    
					- Stephen Frede
					...!decvax!mulga!stephenf:elecvax



More information about the Comp.lang.c mailing list