Is there specific documentation for the behavior of "i=i--" in gcc?
Once again, our best loved "i=i--" -like issues. In C99 we have:
6.5 Expressions #2: Between the previous and next sequence point an object shall have its stored value modified at most once
70) This paragraph renders !!undefined!! statement expressions such as
i = ++i开发者_Go百科 + 1;
But for undefinded behavior there can be variants from random output to "program execution in a documented manner" (c99 3.4.3)
So, the question:
Does gcc document the behavior for i=i++, i=i--, and so on statements?
Actual code is
int main(){int i=2;i=i--;return i;}
GCC does not document this behaviour. The Warning Options page mentions sequence points issues in -Wsequence-point
, but does not hint at well-defined sematics for violations.
GCC does have a nice list of C Implementation Defined Behaviour, but I could not find any reference to this issue here either.
It's left to the back-end implementation to decide what it does. You can use -S
and inspect the generated code to determine the exact sequence of events.
It is not documented but even it it was, I wouldn't want to read it. You should never rely on what a particular implementation does when running into undefined behavior.
why on earth would you want to do that? Seriously. I'm curious.
精彩评论