Is there a difference if I compile the following program using c89 vs c99? I get the same output. Is there really a difference between the two?
#include <stdio.h>
int main ()
{
// Print string to screen.
printf ("Hello World\n");
}
gcc -o helloworld -std=c99 helloworld.c
vs
gcc -o helloworld -std=c89 helloworld.c
//
comments are not a part of C89 but are OK in C99,main()
without returning any value is equivalent to return 0;
in C99, but not so in C89. From N1256 (pdf), 5.1.2.2.3p1:
If the return type of the
main
function is a type compatible withint
, a return from the initial call to the main function is equivalent to calling theexit
function with the value returned by themain
function as its argument; reaching the}
that terminates themain
function returns a value of 0.
So your code has undefined behavior in C89, and well-defined behavior in C99.