Just how undefined is undefined behavior? I've read claims that various C standards allow all behavior after the first undefined behavior to be effectively arbitrary. You'll see people say four basic levels of undefinedness for a statement like i = i++;
:
- "
i
could be eitheri
ori+1
after the statement." - "
i
could hold any value after the statement." - Anything could happen to any values, or execution could halt entirely, but compiling
i = i++;
with specific side effects likesystem("rm -rf /");
is non-conforming. - Absolutely anything could happen, including
system("rm -rf /");
! The trigger-happy filesystem destroying compiler I describe is 100% conforming.
I believe that the answer is not 1, but which is it (if any of these)? If the answer depends on which specific C standard one references then a vector of answers would be nice.
Edit: The linked possible duplicate isn't really the same question (it's more asking if the possibility of undefined behavior along one code path results in undefinedness regardless of the code path), but the answer to this question directly states that the answer is 4 -- namely, undefined really does mean that the standard places no constraints whatsoever on the behavior. I'm not sure why all the downvotes...
Second edit: The second linked question also isn't a duplicate. It's simply asking about why a given statement is undefined (the answer of course being the subtleties of sequence points). Again, this question's top answer directly speaks to my question, albeit with no authoritative citation (unlike the accepted answer).