Import gcc-2.8.1.tar.bz2
[official-gcc.git] / gcc / gcc.info-8
blob3c39a0617e24b038b8becabaef77659a07ac5474
1 This is Info file gcc.info, produced by Makeinfo version 1.67 from the
2 input file gcc.texi.
4    This file documents the use and the internals of the GNU compiler.
6    Published by the Free Software Foundation 59 Temple Place - Suite 330
7 Boston, MA 02111-1307 USA
9    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998
10 Free Software Foundation, Inc.
12    Permission is granted to make and distribute verbatim copies of this
13 manual provided the copyright notice and this permission notice are
14 preserved on all copies.
16    Permission is granted to copy and distribute modified versions of
17 this manual under the conditions for verbatim copying, provided also
18 that the sections entitled "GNU General Public License," "Funding for
19 Free Software," and "Protect Your Freedom--Fight `Look And Feel'" are
20 included exactly as in the original, and provided that the entire
21 resulting derived work is distributed under the terms of a permission
22 notice identical to this one.
24    Permission is granted to copy and distribute translations of this
25 manual into another language, under the above conditions for modified
26 versions, except that the sections entitled "GNU General Public
27 License," "Funding for Free Software," and "Protect Your Freedom--Fight
28 `Look And Feel'", and this permission notice, may be included in
29 translations approved by the Free Software Foundation instead of in the
30 original English.
32 \x1f
33 File: gcc.info,  Node: Cross Runtime,  Next: Build Cross,  Prev: Cross Headers,  Up: Cross-Compiler
35 `libgcc.a' and Cross-Compilers
36 ------------------------------
38    Code compiled by GNU CC uses certain runtime support functions
39 implicitly.  Some of these functions can be compiled successfully with
40 GNU CC itself, but a few cannot be.  These problem functions are in the
41 source file `libgcc1.c'; the library made from them is called
42 `libgcc1.a'.
44    When you build a native compiler, these functions are compiled with
45 some other compiler-the one that you use for bootstrapping GNU CC.
46 Presumably it knows how to open code these operations, or else knows how
47 to call the run-time emulation facilities that the machine comes with.
48 But this approach doesn't work for building a cross-compiler.  The
49 compiler that you use for building knows about the host system, not the
50 target system.
52    So, when you build a cross-compiler you have to supply a suitable
53 library `libgcc1.a' that does the job it is expected to do.
55    To compile `libgcc1.c' with the cross-compiler itself does not work.
56 The functions in this file are supposed to implement arithmetic
57 operations that GNU CC does not know how to open code for your target
58 machine.  If these functions are compiled with GNU CC itself, they will
59 compile into infinite recursion.
61    On any given target, most of these functions are not needed.  If GNU
62 CC can open code an arithmetic operation, it will not call these
63 functions to perform the operation.  It is possible that on your target
64 machine, none of these functions is needed.  If so, you can supply an
65 empty library as `libgcc1.a'.
67    Many targets need library support only for multiplication and
68 division.  If you are linking with a library that contains functions for
69 multiplication and division, you can tell GNU CC to call them directly
70 by defining the macros `MULSI3_LIBCALL', and the like.  These macros
71 need to be defined in the target description macro file.  For some
72 targets, they are defined already.  This may be sufficient to avoid the
73 need for libgcc1.a; if so, you can supply an empty library.
75    Some targets do not have floating point instructions; they need other
76 functions in `libgcc1.a', which do floating arithmetic.  Recent
77 versions of GNU CC have a file which emulates floating point.  With a
78 certain amount of work, you should be able to construct a floating
79 point emulator that can be used as `libgcc1.a'.  Perhaps future
80 versions will contain code to do this automatically and conveniently.
81 That depends on whether someone wants to implement it.
83    Some embedded targets come with all the necessary `libgcc1.a'
84 routines written in C or assembler.  These targets build `libgcc1.a'
85 automatically and you do not need to do anything special for them.
86 Other embedded targets do not need any `libgcc1.a' routines since all
87 the necessary operations are supported by the hardware.
89    If your target system has another C compiler, you can configure GNU
90 CC as a native compiler on that machine, build just `libgcc1.a' with
91 `make libgcc1.a' on that machine, and use the resulting file with the
92 cross-compiler.  To do this, execute the following on the target
93 machine:
95      cd TARGET-BUILD-DIR
96      ./configure --host=sparc --target=sun3
97      make libgcc1.a
99 And then this on the host machine:
101      ftp TARGET-MACHINE
102      binary
103      cd TARGET-BUILD-DIR
104      get libgcc1.a
105      quit
107    Another way to provide the functions you need in `libgcc1.a' is to
108 define the appropriate `perform_...' macros for those functions.  If
109 these definitions do not use the C arithmetic operators that they are
110 meant to implement, you should be able to compile them with the
111 cross-compiler you are building.  (If these definitions already exist
112 for your target file, then you are all set.)
114    To build `libgcc1.a' using the perform macros, use
115 `LIBGCC1=libgcc1.a OLDCC=./xgcc' when building the compiler.
116 Otherwise, you should place your replacement library under the name
117 `libgcc1.a' in the directory in which you will build the
118 cross-compiler, before you run `make'.
120 \x1f
121 File: gcc.info,  Node: Cross Headers,  Next: Cross Runtime,  Prev: Tools and Libraries,  Up: Cross-Compiler
123 Cross-Compilers and Header Files
124 --------------------------------
126    If you are cross-compiling a standalone program or a program for an
127 embedded system, then you may not need any header files except the few
128 that are part of GNU CC (and those of your program).  However, if you
129 intend to link your program with a standard C library such as `libc.a',
130 then you probably need to compile with the header files that go with
131 the library you use.
133    The GNU C compiler does not come with these files, because (1) they
134 are system-specific, and (2) they belong in a C library, not in a
135 compiler.
137    If the GNU C library supports your target machine, then you can get
138 the header files from there (assuming you actually use the GNU library
139 when you link your program).
141    If your target machine comes with a C compiler, it probably comes
142 with suitable header files also.  If you make these files accessible
143 from the host machine, the cross-compiler can use them also.
145    Otherwise, you're on your own in finding header files to use when
146 cross-compiling.
148    When you have found suitable header files, put them in the directory
149 `/usr/local/TARGET/include', before building the cross compiler.  Then
150 installation will run fixincludes properly and install the corrected
151 versions of the header files where the compiler will use them.
153    Provide the header files before you build the cross-compiler, because
154 the build stage actually runs the cross-compiler to produce parts of
155 `libgcc.a'.  (These are the parts that *can* be compiled with GNU CC.)
156 Some of them need suitable header files.
158    Here's an example showing how to copy the header files from a target
159 machine.  On the target machine, do this:
161      (cd /usr/include; tar cf - .) > tarfile
163    Then, on the host machine, do this:
165      ftp TARGET-MACHINE
166      lcd /usr/local/TARGET/include
167      get tarfile
168      quit
169      tar xf tarfile
171 \x1f
172 File: gcc.info,  Node: Build Cross,  Prev: Cross Runtime,  Up: Cross-Compiler
174 Actually Building the Cross-Compiler
175 ------------------------------------
177    Now you can proceed just as for compiling a single-machine compiler
178 through the step of building stage 1.  If you have not provided some
179 sort of `libgcc1.a', then compilation will give up at the point where
180 it needs that file, printing a suitable error message.  If you do
181 provide `libgcc1.a', then building the compiler will automatically
182 compile and link a test program called `libgcc1-test'; if you get
183 errors in the linking, it means that not all of the necessary routines
184 in `libgcc1.a' are available.
186    You must provide the header file `float.h'.  One way to do this is
187 to compile `enquire' and run it on your target machine.  The job of
188 `enquire' is to run on the target machine and figure out by experiment
189 the nature of its floating point representation.  `enquire' records its
190 findings in the header file `float.h'.  If you can't produce this file
191 by running `enquire' on the target machine, then you will need to come
192 up with a suitable `float.h' in some other way (or else, avoid using it
193 in your programs).
195    Do not try to build stage 2 for a cross-compiler.  It doesn't work to
196 rebuild GNU CC as a cross-compiler using the cross-compiler, because
197 that would produce a program that runs on the target machine, not on the
198 host.  For example, if you compile a 386-to-68030 cross-compiler with
199 itself, the result will not be right either for the 386 (because it was
200 compiled into 68030 code) or for the 68030 (because it was configured
201 for a 386 as the host).  If you want to compile GNU CC into 68030 code,
202 whether you compile it on a 68030 or with a cross-compiler on a 386, you
203 must specify a 68030 as the host when you configure it.
205    To install the cross-compiler, use `make install', as usual.
207 \x1f
208 File: gcc.info,  Node: Sun Install,  Next: VMS Install,  Prev: Cross-Compiler,  Up: Installation
210 Installing GNU CC on the Sun
211 ============================
213    On Solaris, do not use the linker or other tools in `/usr/ucb' to
214 build GNU CC.  Use `/usr/ccs/bin'.
216    If the assembler reports `Error: misaligned data' when bootstrapping,
217 you are probably using an obsolete version of the GNU assembler.
218 Upgrade to the latest version of GNU `binutils', or use the Solaris
219 assembler.
221    Make sure the environment variable `FLOAT_OPTION' is not set when
222 you compile `libgcc.a'.  If this option were set to `f68881' when
223 `libgcc.a' is compiled, the resulting code would demand to be linked
224 with a special startup file and would not link properly without special
225 pains.
227    There is a bug in `alloca' in certain versions of the Sun library.
228 To avoid this bug, install the binaries of GNU CC that were compiled by
229 GNU CC.  They use `alloca' as a built-in function and never the one in
230 the library.
232    Some versions of the Sun compiler crash when compiling GNU CC.  The
233 problem is a segmentation fault in cpp.  This problem seems to be due to
234 the bulk of data in the environment variables.  You may be able to avoid
235 it by using the following command to compile GNU CC with Sun CC:
237      make CC="TERMCAP=x OBJS=x LIBFUNCS=x STAGESTUFF=x cc"
239    SunOS 4.1.3 and 4.1.3_U1 have bugs that can cause intermittent core
240 dumps when compiling GNU CC.  A common symptom is an internal compiler
241 error which does not recur if you run it again.  To fix the problem,
242 install Sun recommended patch 100726 (for SunOS 4.1.3) or 101508 (for
243 SunOS 4.1.3_U1), or upgrade to a later SunOS release.
245 \x1f
246 File: gcc.info,  Node: VMS Install,  Next: Collect2,  Prev: Sun Install,  Up: Installation
248 Installing GNU CC on VMS
249 ========================
251    The VMS version of GNU CC is distributed in a backup saveset
252 containing both source code and precompiled binaries.
254    To install the `gcc' command so you can use the compiler easily, in
255 the same manner as you use the VMS C compiler, you must install the VMS
256 CLD file for GNU CC as follows:
258   1. Define the VMS logical names `GNU_CC' and `GNU_CC_INCLUDE' to
259      point to the directories where the GNU CC executables
260      (`gcc-cpp.exe', `gcc-cc1.exe', etc.) and the C include files are
261      kept respectively.  This should be done with the commands:
263           $ assign /system /translation=concealed -
264             disk:[gcc.] gnu_cc
265           $ assign /system /translation=concealed -
266             disk:[gcc.include.] gnu_cc_include
268      with the appropriate disk and directory names.  These commands can
269      be placed in your system startup file so they will be executed
270      whenever the machine is rebooted.  You may, if you choose, do this
271      via the `GCC_INSTALL.COM' script in the `[GCC]' directory.
273   2. Install the `GCC' command with the command line:
275           $ set command /table=sys$common:[syslib]dcltables -
276             /output=sys$common:[syslib]dcltables gnu_cc:[000000]gcc
277           $ install replace sys$common:[syslib]dcltables
279   3. To install the help file, do the following:
281           $ library/help sys$library:helplib.hlb gcc.hlp
283      Now you can invoke the compiler with a command like `gcc /verbose
284      file.c', which is equivalent to the command `gcc -v -c file.c' in
285      Unix.
287    If you wish to use GNU C++ you must first install GNU CC, and then
288 perform the following steps:
290   1. Define the VMS logical name `GNU_GXX_INCLUDE' to point to the
291      directory where the preprocessor will search for the C++ header
292      files.  This can be done with the command:
294           $ assign /system /translation=concealed -
295             disk:[gcc.gxx_include.] gnu_gxx_include
297      with the appropriate disk and directory name.  If you are going to
298      be using a C++ runtime library, this is where its install
299      procedure will install its header files.
301   2. Obtain the file `gcc-cc1plus.exe', and place this in the same
302      directory that `gcc-cc1.exe' is kept.
304      The GNU C++ compiler can be invoked with a command like `gcc /plus
305      /verbose file.cc', which is equivalent to the command `g++ -v -c
306      file.cc' in Unix.
308    We try to put corresponding binaries and sources on the VMS
309 distribution tape.  But sometimes the binaries will be from an older
310 version than the sources, because we don't always have time to update
311 them.  (Use the `/version' option to determine the version number of
312 the binaries and compare it with the source file `version.c' to tell
313 whether this is so.)  In this case, you should use the binaries you get
314 to recompile the sources.  If you must recompile, here is how:
316   1. Execute the command procedure `vmsconfig.com' to set up the files
317      `tm.h', `config.h', `aux-output.c', and `md.', and to create files
318      `tconfig.h' and `hconfig.h'.  This procedure also creates several
319      linker option files used by `make-cc1.com' and a data file used by
320      `make-l2.com'.
322           $ @vmsconfig.com
324   2. Setup the logical names and command tables as defined above.  In
325      addition, define the VMS logical name `GNU_BISON' to point at the
326      to the directories where the Bison executable is kept.  This
327      should be done with the command:
329           $ assign /system /translation=concealed -
330             disk:[bison.] gnu_bison
332      You may, if you choose, use the `INSTALL_BISON.COM' script in the
333      `[BISON]' directory.
335   3. Install the `BISON' command with the command line:
337           $ set command /table=sys$common:[syslib]dcltables -
338             /output=sys$common:[syslib]dcltables -
339             gnu_bison:[000000]bison
340           $ install replace sys$common:[syslib]dcltables
342   4. Type `@make-gcc' to recompile everything (alternatively, submit
343      the file `make-gcc.com' to a batch queue).  If you wish to build
344      the GNU C++ compiler as well as the GNU CC compiler, you must
345      first edit `make-gcc.com' and follow the instructions that appear
346      in the comments.
348   5. In order to use GCC, you need a library of functions which GCC
349      compiled code will call to perform certain tasks, and these
350      functions are defined in the file `libgcc2.c'.  To compile this
351      you should use the command procedure `make-l2.com', which will
352      generate the library `libgcc2.olb'.  `libgcc2.olb' should be built
353      using the compiler built from the same distribution that
354      `libgcc2.c' came from, and `make-gcc.com' will automatically do
355      all of this for you.
357      To install the library, use the following commands:
359           $ library gnu_cc:[000000]gcclib/delete=(new,eprintf)
360           $ library gnu_cc:[000000]gcclib/delete=L_*
361           $ library libgcc2/extract=*/output=libgcc2.obj
362           $ library gnu_cc:[000000]gcclib libgcc2.obj
364      The first command simply removes old modules that will be replaced
365      with modules from `libgcc2' under different module names.  The
366      modules `new' and `eprintf' may not actually be present in your
367      `gcclib.olb'--if the VMS librarian complains about those modules
368      not being present, simply ignore the message and continue on with
369      the next command.  The second command removes the modules that
370      came from the previous version of the library `libgcc2.c'.
372      Whenever you update the compiler on your system, you should also
373      update the library with the above procedure.
375   6. You may wish to build GCC in such a way that no files are written
376      to the directory where the source files reside.  An example would
377      be the when the source files are on a read-only disk.  In these
378      cases, execute the following DCL commands (substituting your
379      actual path names):
381           $ assign dua0:[gcc.build_dir.]/translation=concealed, -
382                    dua1:[gcc.source_dir.]/translation=concealed  gcc_build
383           $ set default gcc_build:[000000]
385      where the directory `dua1:[gcc.source_dir]' contains the source
386      code, and the directory `dua0:[gcc.build_dir]' is meant to contain
387      all of the generated object files and executables.  Once you have
388      done this, you can proceed building GCC as described above.  (Keep
389      in mind that `gcc_build' is a rooted logical name, and thus the
390      device names in each element of the search list must be an actual
391      physical device name rather than another rooted logical name).
393   7. *If you are building GNU CC with a previous version of GNU CC, you
394      also should check to see that you have the newest version of the
395      assembler*.  In particular, GNU CC version 2 treats global constant
396      variables slightly differently from GNU CC version 1, and GAS
397      version 1.38.1 does not have the patches required to work with GCC
398      version 2.  If you use GAS 1.38.1, then `extern const' variables
399      will not have the read-only bit set, and the linker will generate
400      warning messages about mismatched psect attributes for these
401      variables.  These warning messages are merely a nuisance, and can
402      safely be ignored.
404      If you are compiling with a version of GNU CC older than 1.33,
405      specify `/DEFINE=("inline=")' as an option in all the
406      compilations.  This requires editing all the `gcc' commands in
407      `make-cc1.com'.  (The older versions had problems supporting
408      `inline'.)  Once you have a working 1.33 or newer GNU CC, you can
409      change this file back.
411   8. If you want to build GNU CC with the VAX C compiler, you will need
412      to make minor changes in `make-cccp.com' and `make-cc1.com' to
413      choose alternate definitions of `CC', `CFLAGS', and `LIBS'.  See
414      comments in those files.  However, you must also have a working
415      version of the GNU assembler (GNU as, aka GAS) as it is used as
416      the back-end for GNU CC to produce binary object modules and is
417      not included in the GNU CC sources.  GAS is also needed to compile
418      `libgcc2' in order to build `gcclib' (see above); `make-l2.com'
419      expects to be able to find it operational in
420      `gnu_cc:[000000]gnu-as.exe'.
422      To use GNU CC on VMS, you need the VMS driver programs `gcc.exe',
423      `gcc.com', and `gcc.cld'.  They are distributed with the VMS
424      binaries (`gcc-vms') rather than the GNU CC sources.  GAS is also
425      included in `gcc-vms', as is Bison.
427      Once you have successfully built GNU CC with VAX C, you should use
428      the resulting compiler to rebuild itself.  Before doing this, be
429      sure to restore the `CC', `CFLAGS', and `LIBS' definitions in
430      `make-cccp.com' and `make-cc1.com'.  The second generation
431      compiler will be able to take advantage of many optimizations that
432      must be suppressed when building with other compilers.
434    Under previous versions of GNU CC, the generated code would
435 occasionally give strange results when linked with the sharable
436 `VAXCRTL' library.  Now this should work.
438    Even with this version, however, GNU CC itself should not be linked
439 with the sharable `VAXCRTL'.  The version of `qsort' in `VAXCRTL' has a
440 bug (known to be present in VMS versions V4.6 through V5.5) which
441 causes the compiler to fail.
443    The executables are generated by `make-cc1.com' and `make-cccp.com'
444 use the object library version of `VAXCRTL' in order to make use of the
445 `qsort' routine in `gcclib.olb'.  If you wish to link the compiler
446 executables with the shareable image version of `VAXCRTL', you should
447 edit the file `tm.h' (created by `vmsconfig.com') to define the macro
448 `QSORT_WORKAROUND'.
450    `QSORT_WORKAROUND' is always defined when GNU CC is compiled with
451 VAX C, to avoid a problem in case `gcclib.olb' is not yet available.
453 \x1f
454 File: gcc.info,  Node: Collect2,  Next: Header Dirs,  Prev: VMS Install,  Up: Installation
456 `collect2'
457 ==========
459    Many target systems do not have support in the assembler and linker
460 for "constructors"--initialization functions to be called before the
461 official "start" of `main'.  On such systems, GNU CC uses a utility
462 called `collect2' to arrange to call these functions at start time.
464    The program `collect2' works by linking the program once and looking
465 through the linker output file for symbols with particular names
466 indicating they are constructor functions.  If it finds any, it creates
467 a new temporary `.c' file containing a table of them, compiles it, and
468 links the program a second time including that file.
470    The actual calls to the constructors are carried out by a subroutine
471 called `__main', which is called (automatically) at the beginning of
472 the body of `main' (provided `main' was compiled with GNU CC).  Calling
473 `__main' is necessary, even when compiling C code, to allow linking C
474 and C++ object code together.  (If you use `-nostdlib', you get an
475 unresolved reference to `__main', since it's defined in the standard
476 GCC library.  Include `-lgcc' at the end of your compiler command line
477 to resolve this reference.)
479    The program `collect2' is installed as `ld' in the directory where
480 the passes of the compiler are installed.  When `collect2' needs to
481 find the *real* `ld', it tries the following file names:
483    * `real-ld' in the directories listed in the compiler's search
484      directories.
486    * `real-ld' in the directories listed in the environment variable
487      `PATH'.
489    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
490      if specified.
492    * `ld' in the compiler's search directories, except that `collect2'
493      will not execute itself recursively.
495    * `ld' in `PATH'.
497    "The compiler's search directories" means all the directories where
498 `gcc' searches for passes of the compiler.  This includes directories
499 that you specify with `-B'.
501    Cross-compilers search a little differently:
503    * `real-ld' in the compiler's search directories.
505    * `TARGET-real-ld' in `PATH'.
507    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
508      if specified.
510    * `ld' in the compiler's search directories.
512    * `TARGET-ld' in `PATH'.
514    `collect2' explicitly avoids running `ld' using the file name under
515 which `collect2' itself was invoked.  In fact, it remembers up a list
516 of such names--in case one copy of `collect2' finds another copy (or
517 version) of `collect2' installed as `ld' in a second place in the
518 search path.
520    `collect2' searches for the utilities `nm' and `strip' using the
521 same algorithm as above for `ld'.
523 \x1f
524 File: gcc.info,  Node: Header Dirs,  Prev: Collect2,  Up: Installation
526 Standard Header File Directories
527 ================================
529    `GCC_INCLUDE_DIR' means the same thing for native and cross.  It is
530 where GNU CC stores its private include files, and also where GNU CC
531 stores the fixed include files.  A cross compiled GNU CC runs
532 `fixincludes' on the header files in `$(tooldir)/include'.  (If the
533 cross compilation header files need to be fixed, they must be installed
534 before GNU CC is built.  If the cross compilation header files are
535 already suitable for ANSI C and GNU CC, nothing special need be done).
537    `GPLUS_INCLUDE_DIR' means the same thing for native and cross.  It
538 is where `g++' looks first for header files.  The C++ library installs
539 only target independent header files in that directory.
541    `LOCAL_INCLUDE_DIR' is used only for a native compiler.  It is
542 normally `/usr/local/include'.  GNU CC searches this directory so that
543 users can install header files in `/usr/local/include'.
545    `CROSS_INCLUDE_DIR' is used only for a cross compiler.  GNU CC
546 doesn't install anything there.
548    `TOOL_INCLUDE_DIR' is used for both native and cross compilers.  It
549 is the place for other packages to install header files that GNU CC will
550 use.  For a cross-compiler, this is the equivalent of `/usr/include'.
551 When you build a cross-compiler, `fixincludes' processes any header
552 files in this directory.
554 \x1f
555 File: gcc.info,  Node: C Extensions,  Next: C++ Extensions,  Prev: Installation,  Up: Top
557 Extensions to the C Language Family
558 ***********************************
560    GNU C provides several language features not found in ANSI standard
561 C.  (The `-pedantic' option directs GNU CC to print a warning message if
562 any of these features is used.)  To test for the availability of these
563 features in conditional compilation, check for a predefined macro
564 `__GNUC__', which is always defined under GNU CC.
566    These extensions are available in C and Objective C.  Most of them
567 are also available in C++.  *Note Extensions to the C++ Language: C++
568 Extensions, for extensions that apply *only* to C++.
570 * Menu:
572 * Statement Exprs::     Putting statements and declarations inside expressions.
573 * Local Labels::        Labels local to a statement-expression.
574 * Labels as Values::    Getting pointers to labels, and computed gotos.
575 * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
576 * Constructing Calls::  Dispatching a call to another function.
577 * Naming Types::        Giving a name to the type of some expression.
578 * Typeof::              `typeof': referring to the type of an expression.
579 * Lvalues::             Using `?:', `,' and casts in lvalues.
580 * Conditionals::        Omitting the middle operand of a `?:' expression.
581 * Long Long::           Double-word integers--`long long int'.
582 * Complex::             Data types for complex numbers.
583 * Zero Length::         Zero-length arrays.
584 * Variable Length::     Arrays whose length is computed at run time.
585 * Macro Varargs::       Macros with variable number of arguments.
586 * Subscripting::        Any array can be subscripted, even if not an lvalue.
587 * Pointer Arith::       Arithmetic on `void'-pointers and function pointers.
588 * Initializers::        Non-constant initializers.
589 * Constructors::        Constructor expressions give structures, unions
590                          or arrays as values.
591 * Labeled Elements::    Labeling elements of initializers.
592 * Cast to Union::       Casting to union type from any member of the union.
593 * Case Ranges::         `case 1 ... 9' and such.
594 * Function Attributes:: Declaring that functions have no side effects,
595                          or that they can never return.
596 * Function Prototypes:: Prototype declarations and old-style definitions.
597 * C++ Comments::        C++ comments are recognized.
598 * Dollar Signs::        Dollar sign is allowed in identifiers.
599 * Character Escapes::   `\e' stands for the character <ESC>.
600 * Variable Attributes:: Specifying attributes of variables.
601 * Type Attributes::     Specifying attributes of types.
602 * Alignment::           Inquiring about the alignment of a type or variable.
603 * Inline::              Defining inline functions (as fast as macros).
604 * Extended Asm::        Assembler instructions with C expressions as operands.
605                          (With them you can define "built-in" functions.)
606 * Asm Labels::          Specifying the assembler name to use for a C symbol.
607 * Explicit Reg Vars::   Defining variables residing in specified registers.
608 * Alternate Keywords::  `__const__', `__asm__', etc., for header files.
609 * Incomplete Enums::    `enum foo;', with details to follow.
610 * Function Names::      Printable strings which are the name of the current
611                          function.
612 * Return Address::      Getting the return or frame address of a function.
614 \x1f
615 File: gcc.info,  Node: Statement Exprs,  Next: Local Labels,  Up: C Extensions
617 Statements and Declarations in Expressions
618 ==========================================
620    A compound statement enclosed in parentheses may appear as an
621 expression in GNU C.  This allows you to use loops, switches, and local
622 variables within an expression.
624    Recall that a compound statement is a sequence of statements
625 surrounded by braces; in this construct, parentheses go around the
626 braces.  For example:
628      ({ int y = foo (); int z;
629         if (y > 0) z = y;
630         else z = - y;
631         z; })
633 is a valid (though slightly more complex than necessary) expression for
634 the absolute value of `foo ()'.
636    The last thing in the compound statement should be an expression
637 followed by a semicolon; the value of this subexpression serves as the
638 value of the entire construct.  (If you use some other kind of statement
639 last within the braces, the construct has type `void', and thus
640 effectively no value.)
642    This feature is especially useful in making macro definitions "safe"
643 (so that they evaluate each operand exactly once).  For example, the
644 "maximum" function is commonly defined as a macro in standard C as
645 follows:
647      #define max(a,b) ((a) > (b) ? (a) : (b))
649 But this definition computes either A or B twice, with bad results if
650 the operand has side effects.  In GNU C, if you know the type of the
651 operands (here let's assume `int'), you can define the macro safely as
652 follows:
654      #define maxint(a,b) \
655        ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
657    Embedded statements are not allowed in constant expressions, such as
658 the value of an enumeration constant, the width of a bit field, or the
659 initial value of a static variable.
661    If you don't know the type of the operand, you can still do this,
662 but you must use `typeof' (*note Typeof::.) or type naming (*note
663 Naming Types::.).
665 \x1f
666 File: gcc.info,  Node: Local Labels,  Next: Labels as Values,  Prev: Statement Exprs,  Up: C Extensions
668 Locally Declared Labels
669 =======================
671    Each statement expression is a scope in which "local labels" can be
672 declared.  A local label is simply an identifier; you can jump to it
673 with an ordinary `goto' statement, but only from within the statement
674 expression it belongs to.
676    A local label declaration looks like this:
678      __label__ LABEL;
682      __label__ LABEL1, LABEL2, ...;
684    Local label declarations must come at the beginning of the statement
685 expression, right after the `({', before any ordinary declarations.
687    The label declaration defines the label *name*, but does not define
688 the label itself.  You must do this in the usual way, with `LABEL:',
689 within the statements of the statement expression.
691    The local label feature is useful because statement expressions are
692 often used in macros.  If the macro contains nested loops, a `goto' can
693 be useful for breaking out of them.  However, an ordinary label whose
694 scope is the whole function cannot be used: if the macro can be
695 expanded several times in one function, the label will be multiply
696 defined in that function.  A local label avoids this problem.  For
697 example:
699      #define SEARCH(array, target)                     \
700      ({                                               \
701        __label__ found;                                \
702        typeof (target) _SEARCH_target = (target);      \
703        typeof (*(array)) *_SEARCH_array = (array);     \
704        int i, j;                                       \
705        int value;                                      \
706        for (i = 0; i < max; i++)                       \
707          for (j = 0; j < max; j++)                     \
708            if (_SEARCH_array[i][j] == _SEARCH_target)  \
709              { value = i; goto found; }              \
710        value = -1;                                     \
711       found:                                           \
712        value;                                          \
713      })
715 \x1f
716 File: gcc.info,  Node: Labels as Values,  Next: Nested Functions,  Prev: Local Labels,  Up: C Extensions
718 Labels as Values
719 ================
721    You can get the address of a label defined in the current function
722 (or a containing function) with the unary operator `&&'.  The value has
723 type `void *'.  This value is a constant and can be used wherever a
724 constant of that type is valid.  For example:
726      void *ptr;
727      ...
728      ptr = &&foo;
730    To use these values, you need to be able to jump to one.  This is
731 done with the computed goto statement(1), `goto *EXP;'.  For example,
733      goto *ptr;
735 Any expression of type `void *' is allowed.
737    One way of using these constants is in initializing a static array
738 that will serve as a jump table:
740      static void *array[] = { &&foo, &&bar, &&hack };
742    Then you can select a label with indexing, like this:
744      goto *array[i];
746 Note that this does not check whether the subscript is in bounds--array
747 indexing in C never does that.
749    Such an array of label values serves a purpose much like that of the
750 `switch' statement.  The `switch' statement is cleaner, so use that
751 rather than an array unless the problem does not fit a `switch'
752 statement very well.
754    Another use of label values is in an interpreter for threaded code.
755 The labels within the interpreter function can be stored in the
756 threaded code for super-fast dispatching.
758    You can use this mechanism to jump to code in a different function.
759 If you do that, totally unpredictable things will happen.  The best way
760 to avoid this is to store the label address only in automatic variables
761 and never pass it as an argument.
763    ---------- Footnotes ----------
765    (1)  The analogous feature in Fortran is called an assigned goto,
766 but that name seems inappropriate in C, where one can do more than
767 simply store label addresses in label variables.
769 \x1f
770 File: gcc.info,  Node: Nested Functions,  Next: Constructing Calls,  Prev: Labels as Values,  Up: C Extensions
772 Nested Functions
773 ================
775    A "nested function" is a function defined inside another function.
776 (Nested functions are not supported for GNU C++.)  The nested function's
777 name is local to the block where it is defined.  For example, here we
778 define a nested function named `square', and call it twice:
780      foo (double a, double b)
781      {
782        double square (double z) { return z * z; }
783      
784        return square (a) + square (b);
785      }
787    The nested function can access all the variables of the containing
788 function that are visible at the point of its definition.  This is
789 called "lexical scoping".  For example, here we show a nested function
790 which uses an inherited variable named `offset':
792      bar (int *array, int offset, int size)
793      {
794        int access (int *array, int index)
795          { return array[index + offset]; }
796        int i;
797        ...
798        for (i = 0; i < size; i++)
799          ... access (array, i) ...
800      }
802    Nested function definitions are permitted within functions in the
803 places where variable definitions are allowed; that is, in any block,
804 before the first statement in the block.
806    It is possible to call the nested function from outside the scope of
807 its name by storing its address or passing the address to another
808 function:
810      hack (int *array, int size)
811      {
812        void store (int index, int value)
813          { array[index] = value; }
814      
815        intermediate (store, size);
816      }
818    Here, the function `intermediate' receives the address of `store' as
819 an argument.  If `intermediate' calls `store', the arguments given to
820 `store' are used to store into `array'.  But this technique works only
821 so long as the containing function (`hack', in this example) does not
822 exit.
824    If you try to call the nested function through its address after the
825 containing function has exited, all hell will break loose.  If you try
826 to call it after a containing scope level has exited, and if it refers
827 to some of the variables that are no longer in scope, you may be lucky,
828 but it's not wise to take the risk.  If, however, the nested function
829 does not refer to anything that has gone out of scope, you should be
830 safe.
832    GNU CC implements taking the address of a nested function using a
833 technique called "trampolines".
835    A nested function can jump to a label inherited from a containing
836 function, provided the label was explicitly declared in the containing
837 function (*note Local Labels::.).  Such a jump returns instantly to the
838 containing function, exiting the nested function which did the `goto'
839 and any intermediate functions as well.  Here is an example:
841      bar (int *array, int offset, int size)
842      {
843        __label__ failure;
844        int access (int *array, int index)
845          {
846            if (index > size)
847              goto failure;
848            return array[index + offset];
849          }
850        int i;
851        ...
852        for (i = 0; i < size; i++)
853          ... access (array, i) ...
854        ...
855        return 0;
856      
857       /* Control comes here from `access'
858          if it detects an error.  */
859       failure:
860        return -1;
861      }
863    A nested function always has internal linkage.  Declaring one with
864 `extern' is erroneous.  If you need to declare the nested function
865 before its definition, use `auto' (which is otherwise meaningless for
866 function declarations).
868      bar (int *array, int offset, int size)
869      {
870        __label__ failure;
871        auto int access (int *, int);
872        ...
873        int access (int *array, int index)
874          {
875            if (index > size)
876              goto failure;
877            return array[index + offset];
878          }
879        ...
880      }
882 \x1f
883 File: gcc.info,  Node: Constructing Calls,  Next: Naming Types,  Prev: Nested Functions,  Up: C Extensions
885 Constructing Function Calls
886 ===========================
888    Using the built-in functions described below, you can record the
889 arguments a function received, and call another function with the same
890 arguments, without knowing the number or types of the arguments.
892    You can also record the return value of that function call, and
893 later return that value, without knowing what data type the function
894 tried to return (as long as your caller expects that data type).
896 `__builtin_apply_args ()'
897      This built-in function returns a pointer of type `void *' to data
898      describing how to perform a call with the same arguments as were
899      passed to the current function.
901      The function saves the arg pointer register, structure value
902      address, and all registers that might be used to pass arguments to
903      a function into a block of memory allocated on the stack.  Then it
904      returns the address of that block.
906 `__builtin_apply (FUNCTION, ARGUMENTS, SIZE)'
907      This built-in function invokes FUNCTION (type `void (*)()') with a
908      copy of the parameters described by ARGUMENTS (type `void *') and
909      SIZE (type `int').
911      The value of ARGUMENTS should be the value returned by
912      `__builtin_apply_args'.  The argument SIZE specifies the size of
913      the stack argument data, in bytes.
915      This function returns a pointer of type `void *' to data describing
916      how to return whatever value was returned by FUNCTION.  The data
917      is saved in a block of memory allocated on the stack.
919      It is not always simple to compute the proper value for SIZE.  The
920      value is used by `__builtin_apply' to compute the amount of data
921      that should be pushed on the stack and copied from the incoming
922      argument area.
924 `__builtin_return (RESULT)'
925      This built-in function returns the value described by RESULT from
926      the containing function.  You should specify, for RESULT, a value
927      returned by `__builtin_apply'.
929 \x1f
930 File: gcc.info,  Node: Naming Types,  Next: Typeof,  Prev: Constructing Calls,  Up: C Extensions
932 Naming an Expression's Type
933 ===========================
935    You can give a name to the type of an expression using a `typedef'
936 declaration with an initializer.  Here is how to define NAME as a type
937 name for the type of EXP:
939      typedef NAME = EXP;
941    This is useful in conjunction with the statements-within-expressions
942 feature.  Here is how the two together can be used to define a safe
943 "maximum" macro that operates on any arithmetic type:
945      #define max(a,b) \
946        ({typedef _ta = (a), _tb = (b);  \
947          _ta _a = (a); _tb _b = (b);     \
948          _a > _b ? _a : _b; })
950    The reason for using names that start with underscores for the local
951 variables is to avoid conflicts with variable names that occur within
952 the expressions that are substituted for `a' and `b'.  Eventually we
953 hope to design a new form of declaration syntax that allows you to
954 declare variables whose scopes start only after their initializers;
955 this will be a more reliable way to prevent such conflicts.
957 \x1f
958 File: gcc.info,  Node: Typeof,  Next: Lvalues,  Prev: Naming Types,  Up: C Extensions
960 Referring to a Type with `typeof'
961 =================================
963    Another way to refer to the type of an expression is with `typeof'.
964 The syntax of using of this keyword looks like `sizeof', but the
965 construct acts semantically like a type name defined with `typedef'.
967    There are two ways of writing the argument to `typeof': with an
968 expression or with a type.  Here is an example with an expression:
970      typeof (x[0](1))
972 This assumes that `x' is an array of functions; the type described is
973 that of the values of the functions.
975    Here is an example with a typename as the argument:
977      typeof (int *)
979 Here the type described is that of pointers to `int'.
981    If you are writing a header file that must work when included in
982 ANSI C programs, write `__typeof__' instead of `typeof'.  *Note
983 Alternate Keywords::.
985    A `typeof'-construct can be used anywhere a typedef name could be
986 used.  For example, you can use it in a declaration, in a cast, or
987 inside of `sizeof' or `typeof'.
989    * This declares `y' with the type of what `x' points to.
991           typeof (*x) y;
993    * This declares `y' as an array of such values.
995           typeof (*x) y[4];
997    * This declares `y' as an array of pointers to characters:
999           typeof (typeof (char *)[4]) y;
1001      It is equivalent to the following traditional C declaration:
1003           char *y[4];
1005      To see the meaning of the declaration using `typeof', and why it
1006      might be a useful way to write, let's rewrite it with these macros:
1008           #define pointer(T)  typeof(T *)
1009           #define array(T, N) typeof(T [N])
1011      Now the declaration can be rewritten this way:
1013           array (pointer (char), 4) y;
1015      Thus, `array (pointer (char), 4)' is the type of arrays of 4
1016      pointers to `char'.
1018 \x1f
1019 File: gcc.info,  Node: Lvalues,  Next: Conditionals,  Prev: Typeof,  Up: C Extensions
1021 Generalized Lvalues
1022 ===================
1024    Compound expressions, conditional expressions and casts are allowed
1025 as lvalues provided their operands are lvalues.  This means that you
1026 can take their addresses or store values into them.
1028    Standard C++ allows compound expressions and conditional expressions
1029 as lvalues, and permits casts to reference type, so use of this
1030 extension is deprecated for C++ code.
1032    For example, a compound expression can be assigned, provided the last
1033 expression in the sequence is an lvalue.  These two expressions are
1034 equivalent:
1036      (a, b) += 5
1037      a, (b += 5)
1039    Similarly, the address of the compound expression can be taken.
1040 These two expressions are equivalent:
1042      &(a, b)
1043      a, &b
1045    A conditional expression is a valid lvalue if its type is not void
1046 and the true and false branches are both valid lvalues.  For example,
1047 these two expressions are equivalent:
1049      (a ? b : c) = 5
1050      (a ? b = 5 : (c = 5))
1052    A cast is a valid lvalue if its operand is an lvalue.  A simple
1053 assignment whose left-hand side is a cast works by converting the
1054 right-hand side first to the specified type, then to the type of the
1055 inner left-hand side expression.  After this is stored, the value is
1056 converted back to the specified type to become the value of the
1057 assignment.  Thus, if `a' has type `char *', the following two
1058 expressions are equivalent:
1060      (int)a = 5
1061      (int)(a = (char *)(int)5)
1063    An assignment-with-arithmetic operation such as `+=' applied to a
1064 cast performs the arithmetic using the type resulting from the cast,
1065 and then continues as in the previous case.  Therefore, these two
1066 expressions are equivalent:
1068      (int)a += 5
1069      (int)(a = (char *)(int) ((int)a + 5))
1071    You cannot take the address of an lvalue cast, because the use of its
1072 address would not work out coherently.  Suppose that `&(int)f' were
1073 permitted, where `f' has type `float'.  Then the following statement
1074 would try to store an integer bit-pattern where a floating point number
1075 belongs:
1077      *&(int)f = 1;
1079    This is quite different from what `(int)f = 1' would do--that would
1080 convert 1 to floating point and store it.  Rather than cause this
1081 inconsistency, we think it is better to prohibit use of `&' on a cast.
1083    If you really do want an `int *' pointer with the address of `f',
1084 you can simply write `(int *)&f'.
1086 \x1f
1087 File: gcc.info,  Node: Conditionals,  Next: Long Long,  Prev: Lvalues,  Up: C Extensions
1089 Conditionals with Omitted Operands
1090 ==================================
1092    The middle operand in a conditional expression may be omitted.  Then
1093 if the first operand is nonzero, its value is the value of the
1094 conditional expression.
1096    Therefore, the expression
1098      x ? : y
1100 has the value of `x' if that is nonzero; otherwise, the value of `y'.
1102    This example is perfectly equivalent to
1104      x ? x : y
1106 In this simple case, the ability to omit the middle operand is not
1107 especially useful.  When it becomes useful is when the first operand
1108 does, or may (if it is a macro argument), contain a side effect.  Then
1109 repeating the operand in the middle would perform the side effect
1110 twice.  Omitting the middle operand uses the value already computed
1111 without the undesirable effects of recomputing it.
1113 \x1f
1114 File: gcc.info,  Node: Long Long,  Next: Complex,  Prev: Conditionals,  Up: C Extensions
1116 Double-Word Integers
1117 ====================
1119    GNU C supports data types for integers that are twice as long as
1120 `int'.  Simply write `long long int' for a signed integer, or `unsigned
1121 long long int' for an unsigned integer.  To make an integer constant of
1122 type `long long int', add the suffix `LL' to the integer.  To make an
1123 integer constant of type `unsigned long long int', add the suffix `ULL'
1124 to the integer.
1126    You can use these types in arithmetic like any other integer types.
1127 Addition, subtraction, and bitwise boolean operations on these types
1128 are open-coded on all types of machines.  Multiplication is open-coded
1129 if the machine supports fullword-to-doubleword a widening multiply
1130 instruction.  Division and shifts are open-coded only on machines that
1131 provide special support.  The operations that are not open-coded use
1132 special library routines that come with GNU CC.
1134    There may be pitfalls when you use `long long' types for function
1135 arguments, unless you declare function prototypes.  If a function
1136 expects type `int' for its argument, and you pass a value of type `long
1137 long int', confusion will result because the caller and the subroutine
1138 will disagree about the number of bytes for the argument.  Likewise, if
1139 the function expects `long long int' and you pass `int'.  The best way
1140 to avoid such problems is to use prototypes.
1142 \x1f
1143 File: gcc.info,  Node: Complex,  Next: Zero Length,  Prev: Long Long,  Up: C Extensions
1145 Complex Numbers
1146 ===============
1148    GNU C supports complex data types.  You can declare both complex
1149 integer types and complex floating types, using the keyword
1150 `__complex__'.
1152    For example, `__complex__ double x;' declares `x' as a variable
1153 whose real part and imaginary part are both of type `double'.
1154 `__complex__ short int y;' declares `y' to have real and imaginary
1155 parts of type `short int'; this is not likely to be useful, but it
1156 shows that the set of complex types is complete.
1158    To write a constant with a complex data type, use the suffix `i' or
1159 `j' (either one; they are equivalent).  For example, `2.5fi' has type
1160 `__complex__ float' and `3i' has type `__complex__ int'.  Such a
1161 constant always has a pure imaginary value, but you can form any
1162 complex value you like by adding one to a real constant.
1164    To extract the real part of a complex-valued expression EXP, write
1165 `__real__ EXP'.  Likewise, use `__imag__' to extract the imaginary part.
1167    The operator `~' performs complex conjugation when used on a value
1168 with a complex type.
1170    GNU CC can allocate complex automatic variables in a noncontiguous
1171 fashion; it's even possible for the real part to be in a register while
1172 the imaginary part is on the stack (or vice-versa).  None of the
1173 supported debugging info formats has a way to represent noncontiguous
1174 allocation like this, so GNU CC describes a noncontiguous complex
1175 variable as if it were two separate variables of noncomplex type.  If
1176 the variable's actual name is `foo', the two fictitious variables are
1177 named `foo$real' and `foo$imag'.  You can examine and set these two
1178 fictitious variables with your debugger.
1180    A future version of GDB will know how to recognize such pairs and
1181 treat them as a single variable with a complex type.
1183 \x1f
1184 File: gcc.info,  Node: Zero Length,  Next: Variable Length,  Prev: Complex,  Up: C Extensions
1186 Arrays of Length Zero
1187 =====================
1189    Zero-length arrays are allowed in GNU C.  They are very useful as
1190 the last element of a structure which is really a header for a
1191 variable-length object:
1193      struct line {
1194        int length;
1195        char contents[0];
1196      };
1197      
1198      {
1199        struct line *thisline = (struct line *)
1200          malloc (sizeof (struct line) + this_length);
1201        thisline->length = this_length;
1202      }
1204    In standard C, you would have to give `contents' a length of 1, which
1205 means either you waste space or complicate the argument to `malloc'.