Assignment and sequence points: how is this ambiguous?

后端 未结 6 1061
礼貌的吻别
礼貌的吻别 2021-01-21 08:46

Consider the C code a = a = a. There\'s no sequence point for assignment, so this code produces a warning when compiling about an undefined operation on a

6条回答
  •  半阙折子戏
    2021-01-21 09:24

    It is actually the entire program that has "undefined behaviour" after it executes that statement. It's not just about the value of a - the program can do anything, including go into an endless loop, print garbage output or crash.

    "Undefined behaviour" really just means that the C standard no longer places any limits on what the program does. That doesn't stop you reasoning about how a particular compiler might behave when it sees that code, but it's still not a valid C program, and that's what the compiler is warning you about.

提交回复
热议问题