Is (--i == i++) an Undefined Behavior?

后端 未结 8 2010
离开以前
离开以前 2020-12-22 11:06

this question is related to my previous problem. The answer I got was \"It is an Undefined behavior.\"

Please anyone explain:

  • What is an undef
8条回答
  •  一生所求
    2020-12-22 11:42

    Your previous question was tagged [C], so I'm answering based on C, even though the code in your current question doesn't look like C.

    The definition of undefined behavior in C99 says (§3.4.3):
    1 undefined behavior
    behavior, upon use of a nonportable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements

    2 NOTE Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).

    Appendix J.2 of the C standard has a (long -- several pages) list of undefined behavior, though even that still isn't exhaustive. For the most part, undefined behavior means you broke the rules, so the way to know it is to know the rules.

提交回复
热议问题