diff options
author | Joseph Myers <jsm28@cam.ac.uk> | 2000-11-11 10:06:22 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2000-11-11 10:06:22 +0000 |
commit | c1030c7c86a8097c2be12596ad54c8a771c127ab (patch) | |
tree | a4243524d8c87801ea1deed84efd82748c14c149 /gcc/gcc.texi | |
parent | 0babc59ad83dde7de15631c84b666afefd4c32a2 (diff) | |
download | gcc-c1030c7c86a8097c2be12596ad54c8a771c127ab.zip gcc-c1030c7c86a8097c2be12596ad54c8a771c127ab.tar.gz gcc-c1030c7c86a8097c2be12596ad54c8a771c127ab.tar.bz2 |
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
Diffstat (limited to 'gcc/gcc.texi')
-rw-r--r-- | gcc/gcc.texi | 245 |
1 files changed, 199 insertions, 46 deletions
diff --git a/gcc/gcc.texi b/gcc/gcc.texi index 7f99ec4..b466cbb 100644 --- a/gcc/gcc.texi +++ b/gcc/gcc.texi @@ -210,6 +210,7 @@ bugs. It corresponds to GCC version 2.97. @menu @ifset USING * G++ and GCC:: You can compile C or C++ programs. +* Standards:: Language standards supported by GCC. * Invoking GCC:: Command options supported by @samp{gcc}. * Installation:: How to configure, compile and install GCC. * C Extensions:: GNU extensions to the C language family. @@ -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 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 install.texi @@ -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. This is necessary, but doesn't always work smoothly. * 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. * C++ Misunderstandings:: Common misunderstandings with GNU C++. * Protoize Caveats:: Things to watch out for when using @code{protoize}. @@ -1039,7 +1191,7 @@ static int foo; will cause the linker to report an undefined symbol @code{foo}. Although this behavior differs from most other systems, it is not a bug because redefining an @code{extern} variable as @code{static} -is undefined in ANSI C. +is undefined in ISO C. @item 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 because of problems in DEC's versions of the X11 header files @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, -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: @example @@ -1205,7 +1357,7 @@ MALLOC=gmalloc.o @cindex incompatibilities of GCC 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 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. @code{-2147483648} is positive. 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. @item @@ -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. 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{longjmp} incompatibilities @@ -1308,7 +1460,7 @@ foobar ( hack) @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 implement. @@ -1340,7 +1492,7 @@ typedef int foo; typedef long foo bar; @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 by Bison grammar rules rather than C code, the @samp{-traditional} flag cannot alter it. @@ -1370,7 +1522,7 @@ counts as a letter.'', but GCC also allows dollar signs in identifiers. @cindex whitespace @item 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 too. @@ -1397,7 +1549,7 @@ C comment delimited by @samp{/*@dots{}*/}. However, Many user programs contain the declaration @samp{long time ();}. In the 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 -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 @samp{long time ();} is erroneous. @@ -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}. 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 -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. 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. GCC needs to install corrected versions of some system header files. 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 -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. 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. @node Standard Libraries @section Standard Libraries -GCC by itself attempts to be what the ISO/ANSI C standard calls a -@dfn{conforming freestanding implementation}. This means all ANSI -C language features are available, as well as the contents of -@file{float.h}, @file{limits.h}, @file{stdarg.h}, and -@file{stddef.h}. The rest of the C library is supplied by the -vendor of the operating system. If that C library doesn't conform to -the C standards, then your programs might get warnings (especially when -using @samp{-Wall}) that you don't expect. +GCC by itself attempts to be a conforming freestanding implementation. +@xref{Standards,,Language Standards Supported by GCC}, for details of +what this means. Beyond the library facilities required of such an +implementation, the rest of the C library is supplied by the vendor of +the operating system. If that C library doesn't conform to the C +standards, then your programs might get warnings (especially when using +@samp{-Wall}) that you don't expect. For example, the @code{sprintf} function on SunOS 4.1.3 returns @code{char *} while the C standard says that @code{sprintf} returns an @@ -1533,9 +1684,11 @@ function will still return @code{char *}. 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}) -has been ported to a number of operating systems, and provides ANSI/ISO, -POSIX, BSD and SystemV compatibility. You could also ask your operating -system vendor if newer libraries are available. +provides ISO C, POSIX, BSD, SystemV and X/Open compatibility for +GNU/Linux and HURD-based GNU systems; no recent version of it supports +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 @section Disappointments and Misunderstandings @@ -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 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 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. @item @@ -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 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 the time of the call, everything will work fine. @item 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 must have a prototype for the called function in scope at the time of the call. @@ -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} inserts a comment containing @samp{???} each time it finds such a 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. @item @@ -1951,7 +2104,7 @@ you can specify a field width explicitly. Making bitfields unsigned by default on particular machines where ``the 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 alternative dialects of C. @@ -2010,25 +2163,25 @@ Currently, GCC defines @code{__STDC__} as long as you don't use @samp{-traditional}. This provides good results in practice. Programmers normally use conditionals on @code{__STDC__} to ask whether -it is safe to use certain features of ANSI C, such as function -prototypes or ANSI token concatenation. Since plain @samp{gcc} supports -all the features of ANSI C, the correct answer to these questions is +it is safe to use certain features of ISO C, such as function +prototypes or ISO token concatenation. Since plain @samp{gcc} supports +all the features of ISO C, the correct answer to these questions is ``yes''. Some users try to use @code{__STDC__} to check for the availability of -certain library facilities. This is actually incorrect usage in an ANSI -C program, because the ANSI C standard says that a conforming +certain library facilities. This is actually incorrect usage in an ISO +C program, because the ISO C standard says that a conforming freestanding implementation should define @code{__STDC__} even though it does not have the library facilities. @samp{gcc -ansi -pedantic} is a 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. 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 -that claim to support ANSI C, such as @samp{gcc -ansi}---not for other -compilers such as plain @samp{gcc}. Whatever the ANSI C standard says +that claim to support ISO C, such as @samp{gcc -ansi}---not for other +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 for pragmatic reasons, not as a requirement. @@ -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 subsequently used. These programs must test @code{__STDC__} 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. These programs work properly with GNU C++ if @code{__STDC__} is defined. 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 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 @@ -2099,7 +2252,7 @@ arguments @samp{2, 3}, or it might get @samp{3, 2}, or even @samp{2, 2}. @item 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 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. @@ -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 compiler. The @samp{-pedantic} option tells GCC to issue warnings in 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. @xref{Warning Options,,Options to Request or Suppress Warnings}, for @@ -2913,7 +3066,7 @@ Include directives of the form: @noindent are a common source of incompatibility between VAX-C and GCC. VAX-C 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 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. 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 -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. @example @@ -3269,7 +3422,7 @@ stored in memory, and the address of the memory location is passed to the subroutine. @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 values after a @code{longjmp}. And this is all GCC promises to do, because it is very difficult to restore register variables correctly, and @@ -3934,7 +4087,7 @@ used in an expression. @findex MULTIBYTE_CHARS @item MULTIBYTE_CHARS 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 characters. |