Combination with -pedantic
-std=c90
makes gcc accept a superset of C90 (for example the more flexible C99 variable declarations anywhere in the program). In order to make gcc enforce the C90 standard, the
-pedantic
flag needs to also be specified.
This is demonstrated in the following program. It compiles without warning if compiled with either
-
-std=c89
-
-std=c90
-
-std=c99
-
-std=c99 -pedantic
However, if compiled with one of the following, it issues a warning about the
mixed declaration and code:
-
-std=c89 -pedantic
-
-std=c90 -pedantic
/*
gcc -std=c89 variable-declaration.c # OK
gcc -std=c89 -pedantic variable-declaration.c # warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
gcc -std=c90 variable-declaration.c # OK
gcc -std=c90 -pedantic variable-declaration.c # warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement]
gcc -std=c99 variable-declaration.c # OK
gcc -std=c99 -pedantic variable-declaration.c # OK
*/
#include <stdio.h>
int foo() {
return 42;
}
int main() {
printf("Hello world.\n");
int i = foo();
printf("i = %d\n", i);
}