2nd Annual Obfuscated Contest Winners
Morris M. Keesan
keesan at bbnccv.UUCP
Wed Jun 26 02:03:12 AEST 1985
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. See the first paragraph of section 7 of the C Reference
Manual (page 185 of K&R), or Page 81 of the System V "Programming Guide", or
Sections C.3 and C.3.17 of the April 30, 1985 draft ANSI spec. To make this
legal, it must be
expr ? (expr , expr) : expr
or
putchar(b?(main(b/2),-b%2+'0'):10)
-------------------------------------------------------------------------
The program further violates K&R C (although it is legal according to all
versions I've seen of the proposed ANSI spec, and also according to the
System V documentation) by using structure member names non-uniquely; i.e.
the structure member a is used both as an int and as a function pointer,
and b is used as an int and as a structure pointer [ K&R p. 197: ". . . the
same member may appear in two different structures if it has the same type in
both . . ." ]. V7 C compilers blow up on this, complaining of redeclaration
of a and b.
For these two reasons, especially the first, I don't think this program
deserves a prize. Also, this is a bug in the 4.2BSD compiler, and even more
so in the 4.2BSD lint, which should issue a warning even if the compiler is
being forgiving.
--
Morris M. Keesan
keesan at bbn-unix.ARPA
{decvax,ihnp4,etc.}!bbncca!keesan
More information about the Comp.lang.c
mailing list