3

Possible Duplicate:
FAQ : Undefined Behavior and Sequence Points

In C++ there are expressions which look very ugly and bizarre. I was going through an article on a local community and found this expression i = (i, ++i,i) + i; there. Is it expression fine or does it have some kind of problem? i is of a primitive type.

Community
  • 1
  • 1
  • 1
    See http://stackoverflow.com/questions/4176328/faq-undefined-behavior-and-sequence-points. In this case, the final `i` in the expression, the one on the rhs of the `+`, is not sequenced relative to the `++i` in the middle. – Steve Jessop Nov 16 '10 at 13:45
  • Almost every day the same question... – Armen Tsirunyan Nov 16 '10 at 13:46
  • Steve Jessop What do you mean by not sequenced. Can you be a bit more precise? – Brendan Joseph Nov 16 '10 at 13:46
  • @Armen: to be somewhat fair to the questioners, sometimes the expression actually is UB, sometimes it isn't. To be less fair to the questioners: read a book. – Steve Jessop Nov 16 '10 at 13:47
  • 2
    @Brendan: if there's anything in that C++-FAQ question/answers which you don't understand, please ask specific questions about it. – Steve Jessop Nov 16 '10 at 13:47
  • Steve Jessop OK there is already something related here. OK reading it. – Brendan Joseph Nov 16 '10 at 13:49
  • 1
    @Brendan: thanks, appreciated. The problem is that nobody is born understanding sequence points, the standard isn't crystal clear, and apparently they're very badly taught/learned. So the people who answer C and C++ questions on SO get this one a lot. – Steve Jessop Nov 16 '10 at 13:51

0 Answers0