Obscure C code (was Re: Excessive optimization)
ethan.dicks at gmail.com
Thu Dec 2 22:04:50 CST 2010
On Thu, Dec 2, 2010 at 7:48 PM, Fred Cisin <cisin at xenosoft.com> wrote:
> On Thu, 2 Dec 2010, Eric Smith wrote:
>> > A[i++] = i++;
>> I can't quote chapter and verse, but I'm fairly sure the standard will
>> say that the result of that assignment is undefined.
> C can be pretty loose about letting you do such.
There are many things that folks commonly do that are officially
undefined... like strlen(NULL) (that returned 0 on an NCR box but
segfaulted a SPARC - the NCR guys tried to claim it proved the Sun was
broken, but I had to point out that it's undefined).
>> Many programmers would say "I would never write code like that", but
>> I've seen statements like that creep into code as a result of
>> cut-and-paste or global-search-and-replace operations that weren't
>> carefully checked.
> #define SIX 1+5
> #define NINE 8+1
> printf("What you get when you multiply SIX by NINE: %d", (SIX * NINE) );
> "The mice will be furious."
More information about the cctalk