Jessta Roll RSS

Archive

Jun
8th
Mon
permalink

Another cool bug

drealmer:

I just discovered yet another really interesting blog about C/C++, the one of Andrew Koenig (link). In one of his posts, he talks about the following piece of code, where a, b and c are all integers:

if ((c = a - b) != 0) printf("%d", c);

Sometimes, this program might print zero. Any idea why?

The answer is here: (link)

yeah, as a programming language, C, was created based on the idea that the people programming in at already knew the asm for their architecture.

I’ve always thought C wasn’t low level enough. But you can’t solve this problem without getting instruction set specific.