Self-reproducing C programs - (nf)

jim at ism780b.UUCP jim at ism780b.UUCP
Mon Oct 1 14:23:39 AEST 1984


#R:alice:-298800:ism780b:25500021:000:923
ism780b!jim    Sep 30 08:24:00 1984

>It is possible to generate (syntactically invalid) C programs whose error message
>output from cc is identical to the program input.  An easy way is to use the
>following shell script:
>
>echo hi >x
>echo bye >junk.c
>until cmp -s x junk.c
>do      mv x junk.c
>        cc junk.c 2>x
>done
>
>When this terminates, it will have found a fixed-point of the cc command.
>I won't reproduce the output here.  It varies from compiler to compiler,
>and can be more than a hundred lines long.

You mean *if* this terminates.
It seems to me that the "fixed point" is only reached when the file size
limit is reached or if there is an arbitrary limit on the number of error
messages produced, since for most if not all compilers this procedure
is divergent.  Also, a compiler which, .e.g., printed the input line with
the erroneous portion(s) bracketed would diverge on the first line.

-- Jim Balter, INTERACTIVE Systems (ima!jim)



More information about the Comp.lang.c mailing list