Occasionally a valid ANSI/ISO program may be incompatible with the extensions in GNU C. To deal with this situation, the compiler option -ansi disables those GNU extensions which are in conflict with the ANSI/ISO standard. On systems using the GNU C Library (glibc) it also disables extensions to the C standard library. This allows programs written for ANSI/ISO C to be compiled without any unwanted effects from GNU extensions.
For example, here is a valid ANSI/ISO C program which uses a variable called asm:
#include <stdio.h>
int
main (void)
{
const char asm[] = "6502";
printf ("the string asm is '%s'\n", asm);
return 0;
}
The variable name asm is valid under the ANSI/ISO standard, but this program will not compile in GNU C because asm is a GNU C keyword extension (it allows native assembly instructions to be used in C functions). Consequently, it cannot be used as a variable name without giving a compilation error:
$ gcc -Wall ansi.c ansi.c: In function `main': ansi.c:6: parse error before `asm' ansi.c:7: parse error before `asm'
In contrast, using the -ansi option disables the asm keyword extension, and allows the program above to be compiled correctly:
$ gcc -Wall -ansi ansi.c $ ./a.out the string asm is '6502'
For reference, the non-standard keywords and macros defined by the GNU C extensions are asm, inline, typeof, unix and vax. More details can be found in the GCC Reference Manual "Using GCC" (see section Further reading).