From C11 5.1.1.2 Translation phases:
Paragraph 2:
[...] A source file that is not empty shall end in a new-line character, which shall not be immediately preceded by a backslash character before any such splicing takes place.
It means every source file must end with a newline.
Example:
#include <stdio.h>
int main()
{
printf("Hello world\n");
return 0;
}
Above example compiled on Clang using clang prog.c -Wall -Wextra -std=gnu11 -pedantic
command. The compiler generates following warning:
prog.c:7:16: warning: no newline at end of file [-Wnewline-eof]
}
^
It's ok because there is no newline at the end of the source file.
Using gcc prog.c -Wall -Wextra -std=gnu11 -pedantic
command, I compiled the above program on GCC. GCC doesn't generate any warning or error.
So, Why doesn't GCC generate any warning or error?