IOCCC image by Matt Zucker

The International Obfuscated C Code Contest

2011/richards - Most surprisingly portable

Author:

To build:

    make

Bugs and (Mis)features:

The current status of this entry is:

STATUS: doesn’t work with some platforms - please help us fix it

For more detailed information see 2011/richards in bugs.html.

To use:

    echo expression | ./richards

Try:

    ./try.sh

Judges’ remarks:

Oh no, yet another dc-style calculator? (see 2000/dlowe using an embedded Perl interpreter and deemed Worst Abuse of the Rules). Well, this one does it (expression calculation, that is, not the rule abuse) in a different way. The author claims that his calculator does just-in-time compilation. What would you do to prove or disprove his claim without attempting to unravel the source?

Author’s remarks:

This is an implementation of the classic UNIX dc command, the reverse Polish calculator. Actually it’s a pretty bad implementation, since it only implements 32-bit integers (well, sizeof(int)-sized integers). It only implements the commands +, -, *, /, p (only for numbers), register stacks, macros and comparisons. Wow, you’d think I could’ve done better in 2K of code.

OH! I forgot to mention! It’s a JIT.

Wait, don’t stop reading! I know what you’re thinking, platform-specific code is discouraged in IOCCC. But do you see any platform-specific code? There’s no assembler here! This JIT works on a dozen platforms, and the only platform-specific assumptions it makes are that the stack grows down and integers are at least 32-bit.

You will probably get warnings while compiling the code. In particular:

Platforms on which all known/tested optimization levels work with no additional flags:

Platforms which work but not at all optimization levels or needing special flags:

Inventory for 2011/richards

Primary files

Secondary files


Jump to: top