Best Abuse of the C Preprocessor

David Goodenough
anonymous organization
541 Commonwealth Ave,
Newton, MA 02159

Judges' comments:

Compile and run.


echo "to C or not to C" | dg

Some C preprocessors get confused about single quotes in certain cases. In particular, the following source line:


may need to be changed to:


if your C preprocessor botches single quotes in cpp expansions.

Systems that have index() and don’t strchr() (e.g., BSD) should compile with without -Dindex=strchr.

Selected notes from the author:

If my preprocessor could hack it, I could write this as one single line rather than 4, but when I do that I get a complaint “defines nested too deeply”.

Spoiler: (rot13 to read)

Guvf vf nabgure ebg13 wbo (oryvrir vg be abg) - gur #qrsvarf ner n abiry jnl bs nqqvat gbxraf: ‘#qrsvar o12(k) 12 k’ zrnaf gung ng fbzr cbvag va gur fbhepr n 12 vf sbyybjrq ol gur pbzcerffrq arfgrq qrsvarf. Gur o12 trgf gur cerivbhf pbzcerffvba nf na nethzrag, naq cercraqf gur 12, guhf znxvat nabgure fgrc va gur erperngvba bs gur fbhepr. Gur nkk() qrsvarf qb gur fnzr, ohg nqq gbxraf nsgre.

Nf sbe gur ebg13 nytbevguz, vg eryvrf ba vaqrk() gb svaq vs gur punenpgre vf va gur frg N-Mn-m. y[] vf na neenl gung trgf svyyrq jvgu:


Vs vaqrk() fnlf gur pune vf va gur nycunorg, gura kbe gur bssfrg jvgu 16 gb genafyngr, naq bhgchg, bgurejvfr cnff vg hapunatrq.

Copyright © 1990, Landon Curt Noll & Larry Bassel. All Rights Reserved. Permission for personal, educational or non-profit use is granted provided this this copyright and notice are included in its entirety and remains unaltered. All other uses must receive prior permission in writing from both Landon Curt Noll and Larry Bassel.