Is while(1); undefined behavior in C?

后端 未结 4 2019
梦如初夏
梦如初夏 2020-12-01 16:01

In C++11 is it Undefined Behavior, but is it the case in C that while(1); is Undefined Behavior?

4条回答
  •  春和景丽
    2020-12-01 16:07

    After checking in the draft C99 standard, I would say "no", it's not undefined. I can't find any language in the draft that mentions a requirement that iterations end.

    The full text of the paragraph describing the semantics of the iterating statements is:

    An iteration statement causes a statement called the loop body to be executed repeatedly until the controlling expression compares equal to 0.

    I would expect any limitation such as the one specififed for C++11 to appear there, if applicable. There is also a section named "Constraints", which also doesn't mention any such constraint.

    Of course, the actual standard might say something else, although I doubt it.

提交回复
热议问题