Bleh, what a depressing thread. Gustavo, why didn't you bother to
provide all the relevant info, like that you are foolishly compiling
with -O3? Its pretty well known that gcc doesn't always produce correct
output when using optimizations more aggressive than -O2. Stop using
-O3 and suddenly it prints 2 all the time. Looks like this bug is
fixed in gcc 4.2 at least.
And what is with the "answers" being provided guys? Its only 8 lines,
and its not that hard to follow. Guessing random "answers" isn't
usually very helpful, maybe reading it and saying "there's nothing
wrong with that code, are you using compiler optimizations?" would
work better. At least a few people tried it instead of making up
non-existant bugs in the code.
Adam