Why does flowing off the end of a non-void function without returning a value not produce a compiler error?

后端 未结 9 2310
粉色の甜心
粉色の甜心 2020-11-21 07:37

Ever since I realized many years ago, that this doesn\'t produce an error by default (in GCC at least), I\'ve always wondered why?

I understand that you can issue co

9条回答
  •  囚心锁ツ
    2020-11-21 08:15

    Sounds like you need to turn up your compiler warnings:

    $ gcc -Wall -Wextra -Werror -x c -
    int main(void) { return; }
    cc1: warnings being treated as errors
    : In function ‘main’:
    :1: warning: ‘return’ with no value, in function returning non-void
    :1: warning: control reaches end of non-void function
    $
    

提交回复
热议问题