C question: no warning?

main()
{
  printf("Hello World.");
}

Why no warnings are generated in the gcc compiler, although we declare main () with a return type of 'int'

+2
source share
4 answers

Because you are not using the -Wall flag. When you do this, you should get:

foo.c:1: warning: return type defaults tointfoo.c: In functionmain’:
foo.c:1: warning: implicit declaration of functionprintffoo.c:1: warning: incompatible implicit declaration of built-in functionprintffoo.c:1: warning: control reaches end of non-void function
+14
source

You forgot to compile with warnings enabled:

gcc -Wall ...
+2
source

. void main(). :

int main() { printf("Hello world"); return 0; }
+1

, ANSI C89. int.

If you want to compile as C89, but you are warned about using an implicit int, you must pass either -Wimplicit-intas an argument to the command line (or -Wall, which allows this warning along with a number of others).

If you want to compile as C99, you must pass -std=c99and -pedantic-errorsthat will cause a compiler error if you use an implicit int.

0
source

All Articles