C89 vs c99 GCC compiler

前端 未结 3 436
逝去的感伤
逝去的感伤 2020-12-30 10:24

Is there a difference if I compile the following program using c89 vs c99? I get the same output. Is there really a difference between the two?

#include <         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-30 10:50

    • // comments are not a part of C89 but are OK in C99,
    • falling off of main() without returning any value is equivalent to return 0; in C99, but not so in C89. From N1256 (pdf), 5.1.2.2.3p1:

      If the return type of the main function is a type compatible with int, a return from the initial call to the main function is equivalent to calling the exit function with the value returned by the main function as its argument; reaching the } that terminates the main function returns a value of 0.

    So your code has undefined behavior in C89, and well-defined behavior in C99.

提交回复
热议问题