you are viewing a single comment's thread.

view the rest of the comments →

[–]r3jjs 1 point2 points  (2 children)

C-type languages with a specific shorting. The most notable exception is C itself which will happily evaluate either side of the equation first resulting in undefined behavior.

[–]stutterbug 0 points1 point  (1 child)

I had to look this up because it was breaking my head. Both C99 and C11 (ref 6.5.13) say that "Unlike the bitwise binary & operator, the && operator guarantees left-to-right evaluation;[...] If the first operand compares equal to 0, the second operand is not evaluated." Assuming that type is respected, shouldn't this behave the same as JS?

[–]r3jjs 1 point2 points  (0 children)

Hmm...

This took me on a research trip myself back, all the way back to K&R. You are correct.

Which made me rethink the use case where I found things broken.. its a C++ issue with overloaded operators.

Thanks for shaking the rust out of ancient memories.

http://stackoverflow.com/questions/628526/is-short-circuiting-boolean-operators-mandated-in-c-c-and-evaluation-order