Quantcast
Channel: Nikolay Igotti
Viewing all articles
Browse latest Browse all 30

C mini-contest

$
0
0
Go guess, what's behaviour of this code:
intfoo() {while (0) while (1) while (2) ;
}
and this
intfoo() {while (2) while (1) while (0) ;
}
Both are valid C constructs, of course.

PS: Question itself is rather trivial, but at least to me it demonstrates important aspects of how dangerous implicit boundaries of C statements could be.

PPS: actually code which inspired me on this example was this comparison:

while (1) {  } while (0); do {  } while (0);
which looking structurally same in fact are parsed completely differently

Viewing all articles
Browse latest Browse all 30

Trending Articles