2nd Annual Obfuscated Contest Winners

Brian Thomson thomson at uthub.UUCP
Thu Jun 27 00:23:58 AEST 1985


>From Morris Keesan (keesan at bbnccv):

>1. The most obscure program:
>(submitted by Lennart Augustsson <seismo!mcvax!enea!chalmers!augustss> )
>
>is not legal C, even though the 4.2BSD compiler (and presumably other PCC-based
>compilers) processes it as the author apparently intended.
>
>Specifically, the expression
>> putchar(b?main(b/2),-b%2+'0':10)
>is illegal.  My compiler (BBN C/70 C compiler, based on the Dennis Ritchie
>PDP-11 C compiler from V7 UNIX) issues the error message "Illegal conditional".
>A little examination reveals that the error reduces to
>
>	expr ? expr , expr : expr
>
>which is illegal because the comma operator has lower precedence than the
>conditional operator.

No, I think you're wrong.  The relative precedence of operators exists only
to disambiguate possible parses.  In the example you cite there is only
one valid parse, so precedence doesn't come into it.  The "bug", if you
want to call it that, exists in your compiler rather than in PCC.

PCC-based compilers use a more powerful technique [LALR(1)] for
expression parsing than does the Ritchie compiler [simple precedence, if
I remember rightly], and the simpler technique can't quite hack
the language.
-- 
		    Brian Thomson,	    CSRI Univ. of Toronto
		    {linus,ihnp4,uw-beaver,floyd,utzoo}!utcsrgv!uthub!thomson



More information about the Comp.lang.c mailing list