Commit c1030c7c by Joseph Myers Committed by Joseph Myers

gcc.texi, [...]: Add new section discussing language standards...

	* gcc.texi, invoke.texi: Add new section discussing language
	standards; link to it where appropriate; refer to ISO C instead of
	ANSI C.

From-SVN: r37383
parent 0babc59a
2000-11-11 Joseph S. Myers <jsm28@cam.ac.uk>
* gcc.texi, invoke.texi: Add new section discussing language
standards; link to it where appropriate; refer to ISO C instead of
ANSI C.
2000-11-11 Alexandre Oliva <aoliva@redhat.com> 2000-11-11 Alexandre Oliva <aoliva@redhat.com>
* builtins.c (std_expand_builtin_va_start): Take PARM_BOUNDARY * builtins.c (std_expand_builtin_va_start): Take PARM_BOUNDARY
......
...@@ -210,6 +210,7 @@ bugs. It corresponds to GCC version 2.97. ...@@ -210,6 +210,7 @@ bugs. It corresponds to GCC version 2.97.
@menu @menu
@ifset USING @ifset USING
* G++ and GCC:: You can compile C or C++ programs. * G++ and GCC:: You can compile C or C++ programs.
* Standards:: Language standards supported by GCC.
* Invoking GCC:: Command options supported by @samp{gcc}. * Invoking GCC:: Command options supported by @samp{gcc}.
* Installation:: How to configure, compile and install GCC. * Installation:: How to configure, compile and install GCC.
* C Extensions:: GNU extensions to the C language family. * C Extensions:: GNU extensions to the C language family.
...@@ -300,6 +301,157 @@ give you comprehensive C++ source-level editing capabilities ...@@ -300,6 +301,157 @@ give you comprehensive C++ source-level editing capabilities
@c a paragraph or two about it here, and move the index entry down when @c a paragraph or two about it here, and move the index entry down when
@c there is more to point to than the general mention in the 1st par. @c there is more to point to than the general mention in the 1st par.
@node Standards
@chapter Language Standards Supported by GCC
@cindex C standard
@cindex C standards
@cindex ANSI C standard
@cindex ANSI C
@cindex ANSI C89
@cindex C89
@cindex ANSI X3.159-1989
@cindex X3.159-1989
@cindex ISO C standard
@cindex ISO C
@cindex ISO C89
@cindex ISO C90
@cindex ISO/IEC 9899
@cindex ISO 9899
@cindex C90
@cindex ISO C94
@cindex C94
@cindex ISO C95
@cindex C95
@cindex ISO C99
@cindex C99
@cindex ISO C9X
@cindex C9X
@cindex Technical Corrigenda
@cindex TC1
@cindex Technical Corrigendum 1
@cindex TC2
@cindex Technical Corrigendum 2
@cindex AMD1
@cindex freestanding implementation
@cindex freestanding environment
@cindex hosted implementation
@cindex hosted environment
@findex __STDC_HOSTED__
For each language compiled by GCC for which there is a standard, GCC
attempts to follow one or more versions of that standard, possibly
with some limitations.
GCC supports three versions of the C standard, although support for
the most recent version is not yet complete.
The original ANSI C standard (X3.159-1989) was ratified in 1989 and
published in 1990. This standard was ratified as an ISO standard
(ISO/IEC 9899:1990) later in 1990. There were no technical
differences between these publications, although the sections of the
ANSI standard were renumbered and became clauses in the ISO standard.
This standard, in both its forms, is commonly known as @dfn{C89}, or
occasionally as @dfn{C90}, from the dates of ratification. The ANSI
standard, but not the ISO standard, also came with a Rationale
document. To select this standard in GCC, use one of the options
@samp{-ansi}, @samp{-std=c89} or @samp{-std=iso9899:1990}; to obtain
all the diagnostics required by the standard, you should also specify
@samp{-pedantic} (or @samp{-pedantic-errors} if you want them to be
errors rather than warnings). @xref{C Dialect Options,,Options
Controlling C Dialect}.
Errors in the 1990 ISO C standard were corrected in two Technical
Corrigenda published in 1994 and 1996. GCC does not support the
uncorrected version.
An amendment to the 1990 standard was published in 1995. This
amendment added digraphs and @code{__STDC_VERSION__} to the language,
but otherwise concerned the library. This amendment is commonly known
as @dfn{AMD1}; the amended standard is sometimes known as @dfn{C94} or
@dfn{C95}. To select this standard in GCC, use the option
@samp{-std=iso9899:199409} (with, as for other standard versions,
@samp{-pedantic} to receive all required diagnostics).
A new edition of the ISO C standard was published in 1999 as ISO/IEC
9899:1999, and is commonly known as @dfn{C99}. GCC has incomplete
support for this standard version; see
@uref{http://gcc.gnu.org/c99status.html} for details. To select this
standard, use @samp{-std=c99} or @samp{-std=iso9899:1999}. (While in
development, drafts of this standard version were referred to as
@dfn{C9X}.)
GCC also has some limited support for traditional (pre-ISO) C with the
@samp{-traditional} option. This support may be of use for compiling
some very old programs that have not been updated to ISO C, but should
not be used for new programs. It will not work with some modern C
libraries such as the GNU C library.
By default, GCC provides some extensions to the C language that on
rare occasions conflict with the C standard. @xref{C
Extensions,,Extensions to the C Language Family}. Use of the
@samp{-std} options listed above will disable these extensions where
they conflict with the C standard version selected. You may also
select an extended version of the C language explicitly with
@samp{-std=gnu89} (for C89 with GNU extensions) or @samp{-std=gnu99}
(for C99 with GNU extensions). The default, if no C language dialect
options are given, is @samp{-std=gnu89}; this will change to
@samp{-std=gnu99} in some future release when the C99 support is
complete. Some features that are part of the C99 standard are
accepted as extensions in C89 mode.
The ISO C standard defines (in clause 4) two classes of conforming
implementation. A @dfn{conforming hosted implementation} supports the
whole standard including all the library facilities; a @dfn{conforming
freestanding implementation} is only required to provide certain
library facilities: those in @code{<float.h>}, @code{<limits.h>},
@code{<stdarg.h>}, and @code{<stddef.h>}; since AMD1, also those in
@code{<iso646.h>}; and in C99, also those in @code{<stdbool.h>} and
@code{<stdint.h>}. In addition, complex types, added in C99, are not
required for freestanding implementations. The standard also defines
two environments for programs, a @dfn{freestanding environment},
required of all implementations and which may not have library
facilities beyond those required of freestanding implementations,
where the handling of program startup and termination are
implementation-defined, and a @dfn{hosted environment}, which is not
required, in which all the library facilities are provided and startup
is through a function @code{int main (void)} or @code{int main (int,
char *[])}. An OS kernel would be a freestanding environment; a
program using the facilities of an operating system would normally be
in a hosted implementation.
GNU CC aims towards being usable as a conforming freestanding
implementation, or as the compiler for a conforming hosted
implementation. By default, it will act as the compiler for a hosted
implementation, defining @code{__STDC_HOSTED__} as @code{1} and
presuming that when the names of ISO C functions are used, they have
the semantics defined in the standard. To make it act as a conforming
freestanding implementation for a freestanding environment, use the
option @samp{-ffreestanding}; it will then define
@code{__STDC_HOSTED__} to @code{0} and not make assumptions about the
meanings of function names from the standard library. To build an OS
kernel, you may well still need to make your own arrangements for
linking and startup. @xref{C Dialect Options,,Options Controlling C
Dialect}.
GNU CC does not provide the library facilities required only of hosted
implementations, nor yet all the facilities required by C99 of
freestanding implementations; to use the facilities of a hosted
environment, you will need to find them elsewhere (for example, in the
GNU C library). @xref{Standard Libraries,,Standard Libraries}.
For references to Technical Corrigenda, Rationale documents and
information concerning the history of C that is available online, see
@uref{http://gcc.gnu.org/readings.html}
@c FIXME: details of C++ standard.
@c FIXME: definitions of Java and Objective C.
@xref{Language,,The GNU Fortran Language, g77, Using and Porting GNU
Fortran}, for details of the Fortran language supported by GCC.
@xref{References,,Language Definition References, chill, GNU Chill},
for details of the CHILL standard.
@include invoke.texi @include invoke.texi
@include install.texi @include install.texi
...@@ -333,7 +485,7 @@ where people's opinions differ as to what is best. ...@@ -333,7 +485,7 @@ where people's opinions differ as to what is best.
* Fixed Headers:: GNU C uses corrected versions of system header files. * Fixed Headers:: GNU C uses corrected versions of system header files.
This is necessary, but doesn't always work smoothly. This is necessary, but doesn't always work smoothly.
* Standard Libraries:: GNU C uses the system C library, which might not be * Standard Libraries:: GNU C uses the system C library, which might not be
compliant with the ISO/ANSI C standard. compliant with the ISO C standard.
* Disappointments:: Regrettable things we can't change, but not quite bugs. * Disappointments:: Regrettable things we can't change, but not quite bugs.
* C++ Misunderstandings:: Common misunderstandings with GNU C++. * C++ Misunderstandings:: Common misunderstandings with GNU C++.
* Protoize Caveats:: Things to watch out for when using @code{protoize}. * Protoize Caveats:: Things to watch out for when using @code{protoize}.
...@@ -1039,7 +1191,7 @@ static int foo; ...@@ -1039,7 +1191,7 @@ static int foo;
will cause the linker to report an undefined symbol @code{foo}. will cause the linker to report an undefined symbol @code{foo}.
Although this behavior differs from most other systems, it is not a Although this behavior differs from most other systems, it is not a
bug because redefining an @code{extern} variable as @code{static} bug because redefining an @code{extern} variable as @code{static}
is undefined in ANSI C. is undefined in ISO C.
@item @item
AIX on the RS/6000 provides support (NLS) for environments outside of AIX on the RS/6000 provides support (NLS) for environments outside of
...@@ -1165,7 +1317,7 @@ Parse errors may occur compiling X11 on a Decstation running Ultrix 4.2 ...@@ -1165,7 +1317,7 @@ Parse errors may occur compiling X11 on a Decstation running Ultrix 4.2
because of problems in DEC's versions of the X11 header files because of problems in DEC's versions of the X11 header files
@file{X11/Xlib.h} and @file{X11/Xutil.h}. People recommend adding @file{X11/Xlib.h} and @file{X11/Xutil.h}. People recommend adding
@samp{-I/usr/include/mit} to use the MIT versions of the header files, @samp{-I/usr/include/mit} to use the MIT versions of the header files,
using the @samp{-traditional} switch to turn off ANSI C, or fixing the using the @samp{-traditional} switch to turn off ISO C, or fixing the
header files by adding this: header files by adding this:
@example @example
...@@ -1205,7 +1357,7 @@ MALLOC=gmalloc.o ...@@ -1205,7 +1357,7 @@ MALLOC=gmalloc.o
@cindex incompatibilities of GCC @cindex incompatibilities of GCC
There are several noteworthy incompatibilities between GNU C and K&R There are several noteworthy incompatibilities between GNU C and K&R
(non-ANSI) versions of C. The @samp{-traditional} option (non-ISO) versions of C. The @samp{-traditional} option
eliminates many of these incompatibilities, @emph{but not all}, by eliminates many of these incompatibilities, @emph{but not all}, by
telling GNU C to behave like a K&R C compiler. telling GNU C to behave like a K&R C compiler.
...@@ -1242,7 +1394,7 @@ to handle string constants the same way most C compilers do. ...@@ -1242,7 +1394,7 @@ to handle string constants the same way most C compilers do.
@code{-2147483648} is positive. @code{-2147483648} is positive.
This is because 2147483648 cannot fit in the type @code{int}, so This is because 2147483648 cannot fit in the type @code{int}, so
(following the ANSI C rules) its data type is @code{unsigned long int}. (following the ISO C rules) its data type is @code{unsigned long int}.
Negating this value yields 2147483648 again. Negating this value yields 2147483648 again.
@item @item
...@@ -1257,7 +1409,7 @@ string constants. For example, the following macro in GCC ...@@ -1257,7 +1409,7 @@ string constants. For example, the following macro in GCC
will produce output @code{"a"} regardless of what the argument @var{a} is. will produce output @code{"a"} regardless of what the argument @var{a} is.
The @samp{-traditional} option directs GCC to handle such cases The @samp{-traditional} option directs GCC to handle such cases
(among others) in the old-fashioned (non-ANSI) fashion. (among others) in the old-fashioned (non-ISO) fashion.
@cindex @code{setjmp} incompatibilities @cindex @code{setjmp} incompatibilities
@cindex @code{longjmp} incompatibilities @cindex @code{longjmp} incompatibilities
...@@ -1308,7 +1460,7 @@ foobar ( ...@@ -1308,7 +1460,7 @@ foobar (
hack) hack)
@end example @end example
ANSI C does not permit such a construct. It would make sense to support ISO C does not permit such a construct. It would make sense to support
it when @samp{-traditional} is used, but it is too much work to it when @samp{-traditional} is used, but it is too much work to
implement. implement.
...@@ -1340,7 +1492,7 @@ typedef int foo; ...@@ -1340,7 +1492,7 @@ typedef int foo;
typedef long foo bar; typedef long foo bar;
@end example @end example
In ANSI C, this is not allowed: @code{long} and other type modifiers In ISO C, this is not allowed: @code{long} and other type modifiers
require an explicit @code{int}. Because this criterion is expressed require an explicit @code{int}. Because this criterion is expressed
by Bison grammar rules rather than C code, the @samp{-traditional} by Bison grammar rules rather than C code, the @samp{-traditional}
flag cannot alter it. flag cannot alter it.
...@@ -1370,7 +1522,7 @@ counts as a letter.'', but GCC also allows dollar signs in identifiers. ...@@ -1370,7 +1522,7 @@ counts as a letter.'', but GCC also allows dollar signs in identifiers.
@cindex whitespace @cindex whitespace
@item @item
PCC allows whitespace in the middle of compound assignment operators PCC allows whitespace in the middle of compound assignment operators
such as @samp{+=}. GCC, following the ANSI standard, does not such as @samp{+=}. GCC, following the ISO standard, does not
allow this. The difficulty described immediately above applies here allow this. The difficulty described immediately above applies here
too. too.
...@@ -1397,7 +1549,7 @@ C comment delimited by @samp{/*@dots{}*/}. However, ...@@ -1397,7 +1549,7 @@ C comment delimited by @samp{/*@dots{}*/}. However,
Many user programs contain the declaration @samp{long time ();}. In the Many user programs contain the declaration @samp{long time ();}. In the
past, the system header files on many systems did not actually declare past, the system header files on many systems did not actually declare
@code{time}, so it did not matter what type your program declared it to @code{time}, so it did not matter what type your program declared it to
return. But in systems with ANSI C headers, @code{time} is declared to return. But in systems with ISO C headers, @code{time} is declared to
return @code{time_t}, and if that is not the same as @code{long}, then return @code{time_t}, and if that is not the same as @code{long}, then
@samp{long time ();} is erroneous. @samp{long time ();} is erroneous.
...@@ -1451,7 +1603,7 @@ which appear to be two hexadecimal constants separated by the minus ...@@ -1451,7 +1603,7 @@ which appear to be two hexadecimal constants separated by the minus
operator. Actually, this string is a single @dfn{preprocessing token}. operator. Actually, this string is a single @dfn{preprocessing token}.
Each such token must correspond to one token in C. Since this does not, Each such token must correspond to one token in C. Since this does not,
GNU C prints an error message. Although it may appear obvious that what GNU C prints an error message. Although it may appear obvious that what
is meant is an operator and two values, the ANSI C standard specifically is meant is an operator and two values, the ISO C standard specifically
requires that this be treated as erroneous. requires that this be treated as erroneous.
A @dfn{preprocessing token} is a @dfn{preprocessing number} if it A @dfn{preprocessing token} is a @dfn{preprocessing number} if it
...@@ -1469,7 +1621,7 @@ the minus sign. This whitespace will end the preprocessing number. ...@@ -1469,7 +1621,7 @@ the minus sign. This whitespace will end the preprocessing number.
GCC needs to install corrected versions of some system header files. GCC needs to install corrected versions of some system header files.
This is because most target systems have some header files that won't This is because most target systems have some header files that won't
work with GCC unless they are changed. Some have bugs, some are work with GCC unless they are changed. Some have bugs, some are
incompatible with ANSI C, and some depend on special features of other incompatible with ISO C, and some depend on special features of other
compilers. compilers.
Installing GCC automatically creates and installs the fixed header Installing GCC automatically creates and installs the fixed header
...@@ -1516,14 +1668,13 @@ does mean that there's nothing for us to do about them. ...@@ -1516,14 +1668,13 @@ does mean that there's nothing for us to do about them.
@node Standard Libraries @node Standard Libraries
@section Standard Libraries @section Standard Libraries
GCC by itself attempts to be what the ISO/ANSI C standard calls a GCC by itself attempts to be a conforming freestanding implementation.
@dfn{conforming freestanding implementation}. This means all ANSI @xref{Standards,,Language Standards Supported by GCC}, for details of
C language features are available, as well as the contents of what this means. Beyond the library facilities required of such an
@file{float.h}, @file{limits.h}, @file{stdarg.h}, and implementation, the rest of the C library is supplied by the vendor of
@file{stddef.h}. The rest of the C library is supplied by the the operating system. If that C library doesn't conform to the C
vendor of the operating system. If that C library doesn't conform to standards, then your programs might get warnings (especially when using
the C standards, then your programs might get warnings (especially when @samp{-Wall}) that you don't expect.
using @samp{-Wall}) that you don't expect.
For example, the @code{sprintf} function on SunOS 4.1.3 returns For example, the @code{sprintf} function on SunOS 4.1.3 returns
@code{char *} while the C standard says that @code{sprintf} returns an @code{char *} while the C standard says that @code{sprintf} returns an
...@@ -1533,9 +1684,11 @@ function will still return @code{char *}. ...@@ -1533,9 +1684,11 @@ function will still return @code{char *}.
If you need a Standard compliant library, then you need to find one, as If you need a Standard compliant library, then you need to find one, as
GCC does not provide one. The GNU C library (called @code{glibc}) GCC does not provide one. The GNU C library (called @code{glibc})
has been ported to a number of operating systems, and provides ANSI/ISO, provides ISO C, POSIX, BSD, SystemV and X/Open compatibility for
POSIX, BSD and SystemV compatibility. You could also ask your operating GNU/Linux and HURD-based GNU systems; no recent version of it supports
system vendor if newer libraries are available. other systems, though some very old versions did. Version 2.2 of the
GNU C library includes nearly complete C99 support. You could also ask
your operating system vendor if newer libraries are available.
@node Disappointments @node Disappointments
@section Disappointments and Misunderstandings @section Disappointments and Misunderstandings
...@@ -1582,10 +1735,10 @@ But in the definition of @code{foo}, the file-scope type is used ...@@ -1582,10 +1735,10 @@ But in the definition of @code{foo}, the file-scope type is used
because that is available to be inherited. Thus, the definition and because that is available to be inherited. Thus, the definition and
the prototype do not match, and you get an error. the prototype do not match, and you get an error.
This behavior may seem silly, but it's what the ANSI standard specifies. This behavior may seem silly, but it's what the ISO standard specifies.
It is easy enough for you to make your code work by moving the It is easy enough for you to make your code work by moving the
definition of @code{struct mumble} above the prototype. It's not worth definition of @code{struct mumble} above the prototype. It's not worth
being incompatible with ANSI C just to avoid an error for the example being incompatible with ISO C just to avoid an error for the example
shown above. shown above.
@item @item
...@@ -1631,13 +1784,13 @@ reason for this is that in the absence of a prototype in scope, ...@@ -1631,13 +1784,13 @@ reason for this is that in the absence of a prototype in scope,
if the first argument is a floating point, it is passed in a if the first argument is a floating point, it is passed in a
floating point register, rather than an integer register. floating point register, rather than an integer register.
If the code is rewritten to use the ANSI standard @file{stdarg.h} If the code is rewritten to use the ISO standard @file{stdarg.h}
method of variable arguments, and the prototype is in scope at method of variable arguments, and the prototype is in scope at
the time of the call, everything will work fine. the time of the call, everything will work fine.
@item @item
On the H8/300 and H8/300H, variable argument functions must be On the H8/300 and H8/300H, variable argument functions must be
implemented using the ANSI standard @file{stdarg.h} method of implemented using the ISO standard @file{stdarg.h} method of
variable arguments. Furthermore, calls to functions using @file{stdarg.h} variable arguments. Furthermore, calls to functions using @file{stdarg.h}
variable arguments must have a prototype for the called function variable arguments must have a prototype for the called function
in scope at the time of the call. in scope at the time of the call.
...@@ -1829,7 +1982,7 @@ For example, it can't determine argument types for declaring a ...@@ -1829,7 +1982,7 @@ For example, it can't determine argument types for declaring a
pointer-to-function variable; this you must do by hand. @code{protoize} pointer-to-function variable; this you must do by hand. @code{protoize}
inserts a comment containing @samp{???} each time it finds such a inserts a comment containing @samp{???} each time it finds such a
variable; so you can find all such variables by searching for this variable; so you can find all such variables by searching for this
string. ANSI C does not require declaring the argument types of string. ISO C does not require declaring the argument types of
pointer-to-function types. pointer-to-function types.
@item @item
...@@ -1951,7 +2104,7 @@ you can specify a field width explicitly. ...@@ -1951,7 +2104,7 @@ you can specify a field width explicitly.
Making bitfields unsigned by default on particular machines where ``the Making bitfields unsigned by default on particular machines where ``the
ABI standard'' says to do so. ABI standard'' says to do so.
The ANSI C standard leaves it up to the implementation whether a bitfield The ISO C standard leaves it up to the implementation whether a bitfield
declared plain @code{int} is signed or not. This in effect creates two declared plain @code{int} is signed or not. This in effect creates two
alternative dialects of C. alternative dialects of C.
...@@ -2010,25 +2163,25 @@ Currently, GCC defines @code{__STDC__} as long as you don't use ...@@ -2010,25 +2163,25 @@ Currently, GCC defines @code{__STDC__} as long as you don't use
@samp{-traditional}. This provides good results in practice. @samp{-traditional}. This provides good results in practice.
Programmers normally use conditionals on @code{__STDC__} to ask whether Programmers normally use conditionals on @code{__STDC__} to ask whether
it is safe to use certain features of ANSI C, such as function it is safe to use certain features of ISO C, such as function
prototypes or ANSI token concatenation. Since plain @samp{gcc} supports prototypes or ISO token concatenation. Since plain @samp{gcc} supports
all the features of ANSI C, the correct answer to these questions is all the features of ISO C, the correct answer to these questions is
``yes''. ``yes''.
Some users try to use @code{__STDC__} to check for the availability of Some users try to use @code{__STDC__} to check for the availability of
certain library facilities. This is actually incorrect usage in an ANSI certain library facilities. This is actually incorrect usage in an ISO
C program, because the ANSI C standard says that a conforming C program, because the ISO C standard says that a conforming
freestanding implementation should define @code{__STDC__} even though it freestanding implementation should define @code{__STDC__} even though it
does not have the library facilities. @samp{gcc -ansi -pedantic} is a does not have the library facilities. @samp{gcc -ansi -pedantic} is a
conforming freestanding implementation, and it is therefore required to conforming freestanding implementation, and it is therefore required to
define @code{__STDC__}, even though it does not come with an ANSI C define @code{__STDC__}, even though it does not come with an ISO C
library. library.
Sometimes people say that defining @code{__STDC__} in a compiler that Sometimes people say that defining @code{__STDC__} in a compiler that
does not completely conform to the ANSI C standard somehow violates the does not completely conform to the ISO C standard somehow violates the
standard. This is illogical. The standard is a standard for compilers standard. This is illogical. The standard is a standard for compilers
that claim to support ANSI C, such as @samp{gcc -ansi}---not for other that claim to support ISO C, such as @samp{gcc -ansi}---not for other
compilers such as plain @samp{gcc}. Whatever the ANSI C standard says compilers such as plain @samp{gcc}. Whatever the ISO C standard says
is relevant to the design of plain @samp{gcc} without @samp{-ansi} only is relevant to the design of plain @samp{gcc} without @samp{-ansi} only
for pragmatic reasons, not as a requirement. for pragmatic reasons, not as a requirement.
...@@ -2047,13 +2200,13 @@ Programs written to compile with C++-to-C translators get the ...@@ -2047,13 +2200,13 @@ Programs written to compile with C++-to-C translators get the
value of @code{__STDC__} that goes with the C compiler that is value of @code{__STDC__} that goes with the C compiler that is
subsequently used. These programs must test @code{__STDC__} subsequently used. These programs must test @code{__STDC__}
to determine what kind of C preprocessor that compiler uses: to determine what kind of C preprocessor that compiler uses:
whether they should concatenate tokens in the ANSI C fashion whether they should concatenate tokens in the ISO C fashion
or in the traditional fashion. or in the traditional fashion.
These programs work properly with GNU C++ if @code{__STDC__} is defined. These programs work properly with GNU C++ if @code{__STDC__} is defined.
They would not work otherwise. They would not work otherwise.
In addition, many header files are written to provide prototypes in ANSI In addition, many header files are written to provide prototypes in ISO
C but not in traditional C. Many of these header files can work without C but not in traditional C. Many of these header files can work without
change in C++ provided @code{__STDC__} is defined. If @code{__STDC__} change in C++ provided @code{__STDC__} is defined. If @code{__STDC__}
is not defined, they will all fail, and will all need to be changed to is not defined, they will all fail, and will all need to be changed to
...@@ -2099,7 +2252,7 @@ arguments @samp{2, 3}, or it might get @samp{3, 2}, or even @samp{2, 2}. ...@@ -2099,7 +2252,7 @@ arguments @samp{2, 3}, or it might get @samp{3, 2}, or even @samp{2, 2}.
@item @item
Not allowing structures with volatile fields in registers. Not allowing structures with volatile fields in registers.
Strictly speaking, there is no prohibition in the ANSI C standard Strictly speaking, there is no prohibition in the ISO C standard
against allowing structures with volatile fields in registers, but against allowing structures with volatile fields in registers, but
it does not seem to make any sense and is probably not what you wanted it does not seem to make any sense and is probably not what you wanted
to do. So the compiler will give an error message in this case. to do. So the compiler will give an error message in this case.
...@@ -2156,7 +2309,7 @@ however, the C and C++ standards specify that certain extensions are ...@@ -2156,7 +2309,7 @@ however, the C and C++ standards specify that certain extensions are
forbidden, and a diagnostic @emph{must} be issued by a conforming forbidden, and a diagnostic @emph{must} be issued by a conforming
compiler. The @samp{-pedantic} option tells GCC to issue warnings in compiler. The @samp{-pedantic} option tells GCC to issue warnings in
such cases; @samp{-pedantic-errors} says to make them errors instead. such cases; @samp{-pedantic-errors} says to make them errors instead.
This does not mean that @emph{all} non-ANSI constructs get warnings This does not mean that @emph{all} non-ISO constructs get warnings
or errors. or errors.
@xref{Warning Options,,Options to Request or Suppress Warnings}, for @xref{Warning Options,,Options to Request or Suppress Warnings}, for
...@@ -2913,7 +3066,7 @@ Include directives of the form: ...@@ -2913,7 +3066,7 @@ Include directives of the form:
@noindent @noindent
are a common source of incompatibility between VAX-C and GCC. VAX-C are a common source of incompatibility between VAX-C and GCC. VAX-C
treats this much like a standard @code{#include <foobar.h>} directive. treats this much like a standard @code{#include <foobar.h>} directive.
That is incompatible with the ANSI C behavior implemented by GCC: to That is incompatible with the ISO C behavior implemented by GCC: to
expand the name @code{foobar} as a macro. Macro expansion should expand the name @code{foobar} as a macro. Macro expansion should
eventually yield one of the two standard formats for @code{#include}: eventually yield one of the two standard formats for @code{#include}:
...@@ -3054,7 +3207,7 @@ The array ``address'' may not be the address of actual storage. ...@@ -3054,7 +3207,7 @@ The array ``address'' may not be the address of actual storage.
The fact that the symbol is an array may lead to warnings where the The fact that the symbol is an array may lead to warnings where the
variable is used. Insert type casts to avoid the warnings. Here is an variable is used. Insert type casts to avoid the warnings. Here is an
example; it takes advantage of the ANSI C feature allowing macros that example; it takes advantage of the ISO C feature allowing macros that
expand to use the same name as the macro itself. expand to use the same name as the macro itself.
@example @example
...@@ -3269,7 +3422,7 @@ stored in memory, and the address of the memory location is passed to ...@@ -3269,7 +3422,7 @@ stored in memory, and the address of the memory location is passed to
the subroutine. the subroutine.
@cindex @code{longjmp} and automatic variables @cindex @code{longjmp} and automatic variables
If you use @code{longjmp}, beware of automatic variables. ANSI C says that If you use @code{longjmp}, beware of automatic variables. ISO C says that
automatic variables that are not declared @code{volatile} have undefined automatic variables that are not declared @code{volatile} have undefined
values after a @code{longjmp}. And this is all GCC promises to do, values after a @code{longjmp}. And this is all GCC promises to do,
because it is very difficult to restore register variables correctly, and because it is very difficult to restore register variables correctly, and
...@@ -3934,7 +4087,7 @@ used in an expression. ...@@ -3934,7 +4087,7 @@ used in an expression.
@findex MULTIBYTE_CHARS @findex MULTIBYTE_CHARS
@item MULTIBYTE_CHARS @item MULTIBYTE_CHARS
Define this macro to enable support for multibyte characters in the Define this macro to enable support for multibyte characters in the
input to GCC. This requires that the host system support the ANSI C input to GCC. This requires that the host system support the ISO C
library functions for converting multibyte characters to wide library functions for converting multibyte characters to wide
characters. characters.
......
...@@ -695,36 +695,36 @@ from C, such as C++ and Objective C) that the compiler accepts: ...@@ -695,36 +695,36 @@ from C, such as C++ and Objective C) that the compiler accepts:
@table @code @table @code
@cindex ANSI support @cindex ANSI support
@cindex ISO support
@item -ansi @item -ansi
In C mode, support all ANSI standard C programs. In C++ mode, In C mode, support all ISO C89 programs. In C++ mode,
remove GNU extensions that conflict with ISO C++. remove GNU extensions that conflict with ISO C++.
@c shouldn't we be saying "ISO"?
This turns off certain features of GCC that are incompatible with ANSI This turns off certain features of GCC that are incompatible with ISO
C (when compiling C code), or of standard C++ (when compiling C++ code), C (when compiling C code), or of standard C++ (when compiling C++ code),
such as the @code{asm} and @code{typeof} keywords, and such as the @code{asm} and @code{typeof} keywords, and
predefined macros such as @code{unix} and @code{vax} that identify the predefined macros such as @code{unix} and @code{vax} that identify the
type of system you are using. It also enables the undesirable and type of system you are using. It also enables the undesirable and
rarely used ANSI trigraph feature. For the C compiler, rarely used ISO trigraph feature. For the C compiler,
it disables recognition of C++ style @samp{//} comments as well as it disables recognition of C++ style @samp{//} comments as well as
the @code{inline} keyword. the @code{inline} keyword.
The alternate keywords @code{__asm__}, @code{__extension__}, The alternate keywords @code{__asm__}, @code{__extension__},
@code{__inline__} and @code{__typeof__} continue to work despite @code{__inline__} and @code{__typeof__} continue to work despite
@samp{-ansi}. You would not want to use them in an ANSI C program, of @samp{-ansi}. You would not want to use them in an ISO C program, of
course, but it is useful to put them in header files that might be included course, but it is useful to put them in header files that might be included
in compilations done with @samp{-ansi}. Alternate predefined macros in compilations done with @samp{-ansi}. Alternate predefined macros
such as @code{__unix__} and @code{__vax__} are also available, with or such as @code{__unix__} and @code{__vax__} are also available, with or
without @samp{-ansi}. without @samp{-ansi}.
The @samp{-ansi} option does not cause non-ANSI programs to be The @samp{-ansi} option does not cause non-ISO programs to be
rejected gratuitously. For that, @samp{-pedantic} is required in rejected gratuitously. For that, @samp{-pedantic} is required in
addition to @samp{-ansi}. @xref{Warning Options}. addition to @samp{-ansi}. @xref{Warning Options}.
The macro @code{__STRICT_ANSI__} is predefined when the @samp{-ansi} The macro @code{__STRICT_ANSI__} is predefined when the @samp{-ansi}
option is used. Some header files may notice this macro and refrain option is used. Some header files may notice this macro and refrain
from declaring certain functions or defining certain macros that the from declaring certain functions or defining certain macros that the
ANSI standard doesn't call for; this is to avoid interfering with any ISO standard doesn't call for; this is to avoid interfering with any
programs that might use these names for other things. programs that might use these names for other things.
Functions which would normally be builtin but do not have semantics Functions which would normally be builtin but do not have semantics
...@@ -776,6 +776,9 @@ features of newer standards in so far as they do not conflict with ...@@ -776,6 +776,9 @@ features of newer standards in so far as they do not conflict with
previous C standards. For example, you may use @code{__restrict__} even previous C standards. For example, you may use @code{__restrict__} even
when -std=c99 is not specified. when -std=c99 is not specified.
@xref{Standards,,Language Standards Supported by GCC}, for details of
these standard versions.
@item -fno-asm @item -fno-asm
Do not recognize @code{asm}, @code{inline} or @code{typeof} as a Do not recognize @code{asm}, @code{inline} or @code{typeof} as a
keyword, so that code can use these words as identifiers. You can use keyword, so that code can use these words as identifiers. You can use
...@@ -820,8 +823,11 @@ is one in which the standard library may not exist, and program startup may ...@@ -820,8 +823,11 @@ is one in which the standard library may not exist, and program startup may
not necessarily be at @code{main}. The most obvious example is an OS kernel. not necessarily be at @code{main}. The most obvious example is an OS kernel.
This is equivalent to @samp{-fno-hosted}. This is equivalent to @samp{-fno-hosted}.
@xref{Standards,,Language Standards Supported by GCC}, for details of
freestanding and hosted environments.
@item -trigraphs @item -trigraphs
Support ANSI C trigraphs. You don't want to know about this Support ISO C trigraphs. You don't want to know about this
brain-damage. The @samp{-ansi} option implies @samp{-trigraphs}. brain-damage. The @samp{-ansi} option implies @samp{-trigraphs}.
@cindex traditional C language @cindex traditional C language
...@@ -853,7 +859,7 @@ to @code{unsigned int}. ...@@ -853,7 +859,7 @@ to @code{unsigned int}.
Out-of-range floating point literals are not an error. Out-of-range floating point literals are not an error.
@item @item
Certain constructs which ANSI regards as a single invalid preprocessing Certain constructs which ISO regards as a single invalid preprocessing
number, such as @samp{0xe-0xd}, are treated as expressions instead. number, such as @samp{0xe-0xd}, are treated as expressions instead.
@item @item
...@@ -865,7 +871,7 @@ separately. (This is the same as the effect of ...@@ -865,7 +871,7 @@ separately. (This is the same as the effect of
@cindex @code{longjmp} and automatic variables @cindex @code{longjmp} and automatic variables
@item @item
All automatic variables not declared @code{register} are preserved by All automatic variables not declared @code{register} are preserved by
@code{longjmp}. Ordinarily, GNU C follows ANSI C: automatic variables @code{longjmp}. Ordinarily, GNU C follows ISO C: automatic variables
not declared @code{volatile} may be clobbered. not declared @code{volatile} may be clobbered.
@item @item
...@@ -883,8 +889,8 @@ if your program uses names that are normally GNU C builtin functions for ...@@ -883,8 +889,8 @@ if your program uses names that are normally GNU C builtin functions for
other purposes of its own. other purposes of its own.
You cannot use @samp{-traditional} if you include any header files that You cannot use @samp{-traditional} if you include any header files that
rely on ANSI C features. Some vendors are starting to ship systems with rely on ISO C features. Some vendors are starting to ship systems with
ANSI C header files and you cannot use @samp{-traditional} on such ISO C header files and you cannot use @samp{-traditional} on such
systems to compile files that include any system headers. systems to compile files that include any system headers.
The @samp{-traditional} option also enables @samp{-traditional-cpp}, The @samp{-traditional} option also enables @samp{-traditional-cpp},
...@@ -917,7 +923,7 @@ which @code{__GNUC__} indicates are not affected by ...@@ -917,7 +923,7 @@ which @code{__GNUC__} indicates are not affected by
@samp{-traditional}). If you need to write header files that work @samp{-traditional}). If you need to write header files that work
differently depending on whether @samp{-traditional} is in use, by differently depending on whether @samp{-traditional} is in use, by
testing both of these predefined macros you can distinguish four testing both of these predefined macros you can distinguish four
situations: GNU C, traditional GNU C, other ANSI C compilers, and other situations: GNU C, traditional GNU C, other ISO C compilers, and other
old C compilers. The predefined macro @code{__STDC_VERSION__} is also old C compilers. The predefined macro @code{__STDC_VERSION__} is also
not defined when you use @samp{-traditional}. @xref{Standard not defined when you use @samp{-traditional}. @xref{Standard
Predefined,,Standard Predefined Macros,cpp.info,The C Preprocessor}, Predefined,,Standard Predefined Macros,cpp.info,The C Preprocessor},
...@@ -965,8 +971,8 @@ if your program uses names that are normally GNU C builtin functions for ...@@ -965,8 +971,8 @@ if your program uses names that are normally GNU C builtin functions for
other purposes of its own. other purposes of its own.
You cannot use @samp{-traditional} if you include any header files that You cannot use @samp{-traditional} if you include any header files that
rely on ANSI C features. Some vendors are starting to ship systems with rely on ISO C features. Some vendors are starting to ship systems with
ANSI C header files and you cannot use @samp{-traditional} on such ISO C header files and you cannot use @samp{-traditional} on such
systems to compile files that include any system headers. systems to compile files that include any system headers.
@item -fsigned-bitfields @item -fsigned-bitfields
...@@ -1000,7 +1006,7 @@ architecture for which you are compiling, single precision may be faster ...@@ -1000,7 +1006,7 @@ architecture for which you are compiling, single precision may be faster
than double precision. If you must use @samp{-traditional}, but want than double precision. If you must use @samp{-traditional}, but want
to use single precision operations when the operands are single to use single precision operations when the operands are single
precision, use this option. This option has no effect when compiling precision, use this option. This option has no effect when compiling
with ANSI or GNU C conventions (the default). with ISO or GNU C conventions (the default).
@item -fshort-wchar @item -fshort-wchar
Override the underlying type for @samp{wchar_t} to be @samp{short Override the underlying type for @samp{wchar_t} to be @samp{short
...@@ -1062,7 +1068,7 @@ Accept @samp{$} in identifiers. You can also explicitly prohibit use of ...@@ -1062,7 +1068,7 @@ Accept @samp{$} in identifiers. You can also explicitly prohibit use of
@samp{$} with the option @samp{-fno-dollars-in-identifiers}. (GNU C allows @samp{$} with the option @samp{-fno-dollars-in-identifiers}. (GNU C allows
@samp{$} by default on most target systems, but there are a few exceptions.) @samp{$} by default on most target systems, but there are a few exceptions.)
Traditional C allowed the character @samp{$} to form part of Traditional C allowed the character @samp{$} to form part of
identifiers. However, ANSI C and C++ forbid @samp{$} in identifiers. identifiers. However, ISO C and C++ forbid @samp{$} in identifiers.
@item -fno-elide-constructors @item -fno-elide-constructors
The C++ standard allows an implementation to omit creating a temporary The C++ standard allows an implementation to omit creating a temporary
...@@ -1438,7 +1444,7 @@ these escape routes; application programs should avoid them. ...@@ -1438,7 +1444,7 @@ these escape routes; application programs should avoid them.
Some users try to use @samp{-pedantic} to check programs for strict ISO Some users try to use @samp{-pedantic} to check programs for strict ISO
C conformance. They soon find that it does not do quite what they want: C conformance. They soon find that it does not do quite what they want:
it finds some non-ANSI practices, but not all---only those for which it finds some non-ISO practices, but not all---only those for which
ISO C @emph{requires} a diagnostic, and some others for which ISO C @emph{requires} a diagnostic, and some others for which
diagnostics have been added. diagnostics have been added.
...@@ -1841,13 +1847,13 @@ probably mistaken. ...@@ -1841,13 +1847,13 @@ probably mistaken.
@item -Wtraditional (C only) @item -Wtraditional (C only)
Warn about certain constructs that behave differently in traditional and Warn about certain constructs that behave differently in traditional and
ANSI C. ISO C.
@itemize @bullet @itemize @bullet
@item @item
Macro arguments occurring within string constants in the macro body. Macro arguments occurring within string constants in the macro body.
These would substitute the argument in traditional C, but are part of These would substitute the argument in traditional C, but are part of
the constant in ANSI C. the constant in ISO C.
@item @item
A function declared external in one block and then used after the end of A function declared external in one block and then used after the end of
...@@ -1861,13 +1867,13 @@ A non-@code{static} function declaration follows a @code{static} one. ...@@ -1861,13 +1867,13 @@ A non-@code{static} function declaration follows a @code{static} one.
This construct is not accepted by some traditional C compilers. This construct is not accepted by some traditional C compilers.
@item @item
The ANSI type of an integer constant has a different width or The ISO type of an integer constant has a different width or
signedness from its traditional type. This warning is only issued if signedness from its traditional type. This warning is only issued if
the base of the constant is ten. I.e. hexadecimal or octal values, which the base of the constant is ten. I.e. hexadecimal or octal values, which
typically represent bit patterns, are not warned about. typically represent bit patterns, are not warned about.
@item @item
Usage of ANSI string concatenation is detected. Usage of ISO string concatenation is detected.
@item @item
A function macro appears without arguments. A function macro appears without arguments.
...@@ -2703,7 +2709,7 @@ that alter the assembler output may be confused by the optimizations ...@@ -2703,7 +2709,7 @@ that alter the assembler output may be confused by the optimizations
performed when this option is not used. performed when this option is not used.
@item -ffast-math @item -ffast-math
This option allows GCC to violate some ANSI or IEEE rules and/or This option allows GCC to violate some ISO or IEEE rules and/or
specifications in the interest of optimizing code for speed. For specifications in the interest of optimizing code for speed. For
example, it allows the compiler to assume arguments to the @code{sqrt} example, it allows the compiler to assume arguments to the @code{sqrt}
function are non-negative numbers and that no floating-point values function are non-negative numbers and that no floating-point values
...@@ -2711,7 +2717,7 @@ are NaNs. ...@@ -2711,7 +2717,7 @@ are NaNs.
This option should never be turned on by any @samp{-O} option since This option should never be turned on by any @samp{-O} option since
it can result in incorrect output for programs which depend on it can result in incorrect output for programs which depend on
an exact implementation of IEEE or ANSI rules/specifications for an exact implementation of IEEE or ISO rules/specifications for
math functions. math functions.
@item -fno-math-errno @item -fno-math-errno
...@@ -3179,7 +3185,7 @@ Like @samp{-dD} except that the macro arguments and contents are omitted. ...@@ -3179,7 +3185,7 @@ Like @samp{-dD} except that the macro arguments and contents are omitted.
Only @samp{#define @var{name}} is included in the output. Only @samp{#define @var{name}} is included in the output.
@item -trigraphs @item -trigraphs
Support ANSI C trigraphs. The @samp{-ansi} option also has this effect. Support ISO C trigraphs. The @samp{-ansi} option also has this effect.
@item -Wp,@var{option} @item -Wp,@var{option}
Pass @var{option} as an option to the preprocessor. If @var{option} Pass @var{option} as an option to the preprocessor. If @var{option}
...@@ -3263,7 +3269,7 @@ Do not use the standard system libraries when linking. ...@@ -3263,7 +3269,7 @@ Do not use the standard system libraries when linking.
Only the libraries you specify will be passed to the linker. Only the libraries you specify will be passed to the linker.
The standard startup files are used normally, unless @code{-nostartfiles} The standard startup files are used normally, unless @code{-nostartfiles}
is used. The compiler may generate calls to memcmp, memset, and memcpy is used. The compiler may generate calls to memcmp, memset, and memcpy
for System V (and ANSI C) environments or to bcopy and bzero for for System V (and ISO C) environments or to bcopy and bzero for
BSD environments. These entries are usually resolved by entries in BSD environments. These entries are usually resolved by entries in
libc. These entry points should be supplied through some other libc. These entry points should be supplied through some other
mechanism when this option is specified. mechanism when this option is specified.
...@@ -3272,7 +3278,7 @@ mechanism when this option is specified. ...@@ -3272,7 +3278,7 @@ mechanism when this option is specified.
Do not use the standard system startup files or libraries when linking. Do not use the standard system startup files or libraries when linking.
No startup files and only the libraries you specify will be passed to No startup files and only the libraries you specify will be passed to
the linker. The compiler may generate calls to memcmp, memset, and memcpy the linker. The compiler may generate calls to memcmp, memset, and memcpy
for System V (and ANSI C) environments or to bcopy and bzero for for System V (and ISO C) environments or to bcopy and bzero for
BSD environments. These entries are usually resolved by entries in BSD environments. These entries are usually resolved by entries in
libc. These entry points should be supplied through some other libc. These entry points should be supplied through some other
mechanism when this option is specified. mechanism when this option is specified.
...@@ -3655,7 +3661,7 @@ current target machine. Use this when running @code{cpp}. ...@@ -3655,7 +3661,7 @@ current target machine. Use this when running @code{cpp}.
@item %P @item %P
Like @samp{%p}, but puts @samp{__} before and after the name of each Like @samp{%p}, but puts @samp{__} before and after the name of each
predefined macro, except for macros that start with @samp{__} or with predefined macro, except for macros that start with @samp{__} or with
@samp{_@var{L}}, where @var{L} is an uppercase letter. This is for ANSI @samp{_@var{L}}, where @var{L} is an uppercase letter. This is for ISO
C. C.
@item %I @item %I
...@@ -7870,7 +7876,7 @@ recognize and translate multibyte characters. ...@@ -7870,7 +7876,7 @@ recognize and translate multibyte characters.
@section Running Protoize @section Running Protoize
The program @code{protoize} is an optional part of GNU C. You can use The program @code{protoize} is an optional part of GNU C. You can use
it to add prototypes to a program, thus converting the program to ANSI it to add prototypes to a program, thus converting the program to ISO
C in one respect. The companion program @code{unprotoize} does the C in one respect. The companion program @code{unprotoize} does the
reverse: it removes argument types from any prototypes that are found. reverse: it removes argument types from any prototypes that are found.
...@@ -7905,7 +7911,7 @@ are called. ...@@ -7905,7 +7911,7 @@ are called.
Basic conversion with @code{unprotoize} consists of rewriting most Basic conversion with @code{unprotoize} consists of rewriting most
function declarations to remove any argument types, and rewriting function declarations to remove any argument types, and rewriting
function definitions to the old-style pre-ANSI form. function definitions to the old-style pre-ISO form.
Both conversion programs print a warning for any function declaration or Both conversion programs print a warning for any function declaration or
definition that they can't convert. You can suppress these warnings definition that they can't convert. You can suppress these warnings
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment