[comp.lang.c] preprocessor fun

henry@utzoo.uucp (Henry Spencer) (04/08/89)

Consider:

	#ifdef notdef
	#hahafooledyou
	#endif

Clearly this is some sort of error, an unrecognized directive, even though
the text in the #ifdef is being skipped.

Or is it?  Show me where it says that the middle line is a directive at all.
I claim that it is two preprocessing tokens which do not happen to be a
directive.  Nowhere does the Oct. draft say that *only* directives can begin
with "#", or that all lines starting with "#" are directives.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

henry@utzoo.uucp (Henry Spencer) (04/10/89)

In article <1989Apr7.192628.4547@utzoo.uucp> I wrote:
>	#ifdef notdef
>	#hahafooledyou
>	#endif
>
>... Show me where it says that the middle line is a directive at all.
>I claim that it is two preprocessing tokens which do not happen to be a
>directive...

To head off a swarm of wrong followups, there is indeed a rule which
says that the "#" punctuator cannot appear except in directives.  However,
the "#" in the middle line is not a punctuator -- it falls under the
"non-white-space character which cannot be any of the above" class of
preprocessor token.  Said rule is, of course, the reason why it cannot
be a punctuator.

Note that it is crucial that the funny non-directive be #ifdefed out,
because that preprocessing token can't be converted to a real token.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

diamond@diamond.csl.sony.junet (Norman Diamond) (04/10/89)

In article <1989Apr7.192628.4547@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes:

>	#ifdef notdef
>	#hahafooledyou
>	#endif

>Show me where it says that the middle line is a directive at all.
>I claim that it is two preprocessing tokens which do not happen to be a
>directive.  Nowhere does the Oct. draft say that *only* directives can
>begin with "#", or that all lines starting with "#" are directives.

The third line is also two preprocessing tokens.  Yup, a vendor can sell
a compiler that does lots of unexpected things, and point out that it
conforms to the standard.  Let's let the vendor pay her development
costs and take her choice; customers have choices too.

Norman Diamond, Sony Computer Science Lab (diamond%csl.sony.jp@relay.cs.net)
  The above opinions are my own.   |  Why are programmers criticized for
  If they're also your opinions,   |  re-inventing the wheel, when car
  you're infringing my copyright.  |  manufacturers are praised for it?

henry@utzoo.uucp (Henry Spencer) (04/11/89)

In article <10152@socslgw.csl.sony.JUNET> diamond@diamond. (Norman Diamond) writes:
>>	#ifdef notdef
>>	#hahafooledyou
>>	#endif
>
>The third line is also two preprocessing tokens.  Yup, a vendor can sell
>a compiler that does lots of unexpected things, and point out that it
>conforms to the standard...

Thing is, it would appear that a compiler which *refuses* to compile
this DOES NOT conform to the standard and cannot legitimately claim
compliance.  The above three lines are a strictly conforming program,
containing nothing that is illegal, undefined, implementation-defined,
etc etc.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

henry@utzoo.uucp (Henry Spencer) (04/11/89)

In article <9095@elsie.UUCP> ado@elsie.UUCP (Arthur David Olson) writes:
>The goal is to ensure that when
>
>	#if __STDC__ > 1
>	#directive_present_in_C94_though_not_in_C89
>	#endif /* __STDC__ > 1 */
>
>gets written some time in 1985, the "right thing" happens on pre-'84 compilers.

However, the line about the # punctuator only appearing in preprocessor
directives strongly suggests that this wasn't the intent of the person
who wrote that; the above is legal only through a loophole (# doesn't
have to be a punctuator).  There seems to be some confusion about intent.
-- 
Welcome to Mars!  Your         |     Henry Spencer at U of Toronto Zoology
passport and visa, comrade?    | uunet!attcan!utzoo!henry henry@zoo.toronto.edu