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 calledasm
:
#include <stdio.h>intmain (void){ const char asm[] = "6502"; printf ("the string asm is '%s'\n", asm); return 0;}
The variable nameasm
Is valid under the ANSI/ISO standard, but this program will not compile in gnu c becauseasm
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.cansi.c: In function `main':ansi.c:6: parse error before `asm'ansi.c:7: parse error before `asm'
In contrast, using-ansi
Option disablesasm
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 areasm
,inline
,typeof
,unix
Andvax
. More details can be found in the GCC Reference Manual"Using gcc"(See section further reading ).