Next: Incomplete Enums, Previous: Using Assembly Language with C, Up: C Extensions [Contents][Index]
-ansi and the various -std options disable certain keywords. This causes trouble when you want to use GNU C extensions, or a general-purpose header file that should be usable by all programs, including ISO C programs. The keywords asm
, typeof
and inline
are not available in programs compiled with -ansi or -std (although inline
can be used in a program compiled with -std=c99 or a later standard). The ISO C99 keyword restrict
is only available when -std=gnu99 (which will eventually be the default) or -std=c99 (or the equivalent -std=iso9899:1999), or an option for a later standard version, is used.
The way to solve these problems is to put __ at the beginning and end of each problematical keyword. For example, use __asm__
instead of asm
, and __inline__
instead of inline
.
Other C compilers wont accept these alternative keywords; if you want to compile with another compiler, you can define the alternate keywords as macros to replace them with the customary keywords. It looks like this:
#ifndef __GNUC__ #define __asm__ asm #endif
-pedantic and other options cause warnings for many GNU C extensions. You can suppress such warnings using the keyword __extension__
. Specifically:
__extension__
before an expression prevents warnings about extensions within that expression.[[__extension__ ]]
suppresses warnings about using [[]] attributes in C versions that predate C23.
__extension__
has no effect aside from this.