What's the reason for letting the semantics of a=a++ be undefined?

后端 未结 8 1541
后悔当初
后悔当初 2020-12-08 07:18
a = a++;

is undefined behaviour in C. The question I am asking is : why?

I mean, I get that it might be hard to provide a

8条回答
  •  醉话见心
    2020-12-08 07:55

    The postfix ++ operator returns the value prior to the incrementation. So, at the first step, a gets assigned to its old value (that's what ++ returns). At the next point it is undefined whether the increment or the assignment will take place first, because both operations are applied over the same object (a), and the language says nothing about the order of evaluation of these operators.

提交回复
热议问题