Obscure C code (was Re: Excessive optimization)
ethan.dicks at gmail.com
Thu Dec 2 22:46:58 CST 2010
On Thu, Dec 2, 2010 at 11:15 PM, Chuck Guzis <cclist at sydex.com> wrote:
> c = a/*p; /* divide 10/2 */
> ; /* null statements are legal in C */
> Digraphs are nasty.
There was a good example of that sort of thing and an intentionally
obsoleted feature of C interacting badly in a VAX-C tutorial...
It was something like...
printf("i is %d\n", i);
... it worked *if* you loaded the program with the debugger, otherwise
you got a seemingly large and random value for i.
The trick is the "=-" was originally (like c. 1972) the syntax for
what's now "-=" and that took precedence over the seemingly obvious
interpretation of "i = -1" (note the spaces). The reason it worked in
the debugger was that as part of the debugging process, the program
loader would clear out one page of the stack frame with zeros so you
could see autovariables populate the stack area, so the result was a
zero in memory "minus equals" one, or negative one (-1).
Later versions of VAX-C (and other C compilers) complain about
non-initialized autovariables and obsolete language features (like =-
and =+), but the compiler at the time did something odd but
quasi-legal and did it quietly.
More information about the cctalk