I run the following C codes and got a warning: control reaches end of non-void function
int main(void) {}
Any suggestions?
As an alternative to the obvious solution of adding a return
statement to main()
, you can use a C99 compiler (“gcc -std=c99” if you are using GCC).
In C99 it is legal for main()
not to have a return
statement, and then the final }
implicitly returns 0.
$ gcc -c -Wall t.c
t.c: In function ‘main’:
t.c:20: warning: control reaches end of non-void function
$ gcc -c -Wall -std=c99 t.c
$
A note that purists would consider important: you should not fix the warning by declaring main()
as returning type void
.