News for hackers. Stuff that matters.
Re:Both true and false: a Zen moment with C by AshleysBrain on Wednesday June 27, 2012 @10:50AM (#4167223)
Heh, interesting. So I guess it's also possible that "b && !b" evaluates to true... which is probably more ammo for C detractors.
Re:Both true and false: a Zen moment with C by simias on Wednesday June 27, 2012 @10:59AM (#4167303)
That one does not work with g++ and actually does not produce a warning with -Wall without optimisations.

It makes me wonder if that's actually undefined behaviour in C++, because unlike the example in the fine article this time the behaviour of the program does not depend on the (undefined) value of b. Or maybe it's just g++ being clever.

Re:Both true and false: a Zen moment with C by JamesLeonis on Wednesday June 27, 2012 @03:14PM (#4168680)
There is plenty of undefined behavior in C++ [1]. It is important to understand that these aren't bugs in a particular compiler, but deliberate definitions in the standard itself to give compiler writers leeway in their implementations. Amusingly, that means "undefined behavior" is explicitly defined in the standard.

http://stackoverflow.com/a/367662/712512

Re:Both true and false: a Zen moment with C by kd0amg on Wednesday June 27, 2012 @01:43PM (#4168088)
On the other hand, a strength reduction pass might just collapse it to false.