Hex
Hex

Reputation: 87

GCC not warning although it should

I have a very simple Hello World program, that doesn't have a return at the end of its main() function. If I understand correctly, this should throw a Wreturn-type warning, but when I compile it, no output at all is given. It simply compiles it and is done.

program:

#include <stdio.h>
int main() {
  printf("Hello World!\n");
}

compilation commmand:

gcc -Wall -Wextra -o hello.o hello.c

I also tried specifically with the Wreturn-type option.

On Manjaro 18.0.0 with GCC 8.2.1

Upvotes: 3

Views: 103

Answers (1)

pmg
pmg

Reputation: 108978

Use

gcc -std=c89 -pedantic ...

because in C99 1 main() does not need a return 0;. It's as if there was one right before the closing brace.

Upvotes: 6

Related Questions