CC bug test

Kevin Szabo ksbszabo at wateng.UUCP
Mon Feb 4 13:28:50 AEST 1985


In article <780 at sdcsla.UUCP> west at sdcsla.UUCP (Larry West) writes:
>In article <2479686f.8e4 at apollo.uucp> nazgul at apollo.uucp (Kee Hinckley) writes:
>>main()
>>{
>>    printf("Currently compiling only");
>>#ifdef V4
>>    printf(" V4");
>>#endif
>>#ifdef V4.1
>>    printf(" V4.1");
>>#endif
>>#ifdef V4.2
>>    printf(" V4.2");
>>#endif
>>    printf(" lines.\n");
>>}
>
>Hmmm.   On both our Vax and Sun (both 4.2bsd, more or less), the result
>of running this program is: "Currently compiling only lines.".

Well, on our BSD4.2 machine, the following command sequence
	cc -DV.2 test.c; a.out
produces:
	Currently compiling only V4 V4.1 V4.2 lines.

as the original author stated. To repeat the author (in case anybody
missed the original posting). A `.' (period) is not legal part of an
identifier, either in the preprocessor or in C. BSD software allows
you to use a period in preprocessor identifiers, but it quietly truncates
the period and trailing part of the string. Could cause some confusing
bugs...

					Kevin

P.S. Plug time: In Henry Spencer's annotated Indian Hill C Style and Coding
standards he states: If you #ifdef dependencies, make sure that if no machine
is specified, the result is a syntax error, not a default machine.
..Why am I saying this? I don't know, just seemed like a good time to spout
off. I know that following this advice has saved some users of my code a
good deal of heartache..
-- 
Kevin Szabo  watmath!wateng!ksbszabo (U of Waterloo VLSI Group, Waterloo Ont.)



More information about the Comp.lang.c mailing list