Reaching end of function without return statement

后端 未结 2 1868
庸人自扰
庸人自扰 2021-01-06 06:05

ANSI X3.159-1989, section 3.6.6.4, lines 33-35 state:

“If a return statement without an expression is executed, and the value of the function call

相关标签:
2条回答
  • 2021-01-06 06:45

    In both C99 TC2 and C11 it is 6.9.1/12:

    If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.

    In C++11 and C++14 it is [stmt.return]/2:

    Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function

    0 讨论(0)
  • 2021-01-06 07:01

    As to the first sentence (your source appears to be wrong or outdated):

    C 2011 6.8.6.4 The return statement

    1 A return statement with an expression shall not appear in a function whose return type is void. A return statement without an expression shall only appear in a function whose return type is void.

    As to the second sentence:

    C 2011 6.9.1 Function definitions

    12 If the } that terminates a function is reached, and the value of the function call is used by the caller, the behavior is undefined.

    0 讨论(0)
提交回复
热议问题