home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / gcc-2.6.0-src.lha / GNU / src / amiga / gcc-2.6.0 / gcc.info-7 < prev    next >
Encoding:
GNU Info File  |  1994-07-15  |  49.6 KB  |  1,286 lines

  1. This is Info file gcc.info, produced by Makeinfo-1.54 from the input
  2. file gcc.texi.
  3.  
  4.    This file documents the use and the internals of the GNU compiler.
  5.  
  6.    Published by the Free Software Foundation 675 Massachusetts Avenue
  7. Cambridge, MA 02139 USA
  8.  
  9.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  10.  
  11.    Permission is granted to make and distribute verbatim copies of this
  12. manual provided the copyright notice and this permission notice are
  13. preserved on all copies.
  14.  
  15.    Permission is granted to copy and distribute modified versions of
  16. this manual under the conditions for verbatim copying, provided also
  17. that the sections entitled "GNU General Public License" and "Protect
  18. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  19. original, and provided that the entire resulting derived work is
  20. distributed under the terms of a permission notice identical to this
  21. one.
  22.  
  23.    Permission is granted to copy and distribute translations of this
  24. manual into another language, under the above conditions for modified
  25. versions, except that the sections entitled "GNU General Public
  26. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  27. permission notice, may be included in translations approved by the Free
  28. Software Foundation instead of in the original English.
  29.  
  30. 
  31. File: gcc.info,  Node: VMS Install,  Next: Collect2,  Prev: Sun Install,  Up: Installation
  32.  
  33. Installing GNU CC on VMS
  34. ========================
  35.  
  36.    The VMS version of GNU CC is distributed in a backup saveset
  37. containing both source code and precompiled binaries.
  38.  
  39.    To install the `gcc' command so you can use the compiler easily, in
  40. the same manner as you use the VMS C compiler, you must install the VMS
  41. CLD file for GNU CC as follows:
  42.  
  43.   1. Define the VMS logical names `GNU_CC' and `GNU_CC_INCLUDE' to
  44.      point to the directories where the GNU CC executables
  45.      (`gcc-cpp.exe', `gcc-cc1.exe', etc.) and the C include files are
  46.      kept respectively.  This should be done with the commands:
  47.  
  48.           $ assign /system /translation=concealed -
  49.             disk:[gcc.] gnu_cc
  50.           $ assign /system /translation=concealed -
  51.             disk:[gcc.include.] gnu_cc_include
  52.  
  53.      with the appropriate disk and directory names.  These commands can
  54.      be placed in your system startup file so they will be executed
  55.      whenever the machine is rebooted.  You may, if you choose, do this
  56.      via the `GCC_INSTALL.COM' script in the `[GCC]' directory.
  57.  
  58.   2. Install the `GCC' command with the command line:
  59.  
  60.           $ set command /table=sys$common:[syslib]dcltables -
  61.             /output=sys$common:[syslib]dcltables gnu_cc:[000000]gcc
  62.           $ install replace sys$common:[syslib]dcltables
  63.  
  64.   3. To install the help file, do the following:
  65.  
  66.           $ library/help sys$library:helplib.hlb gcc.hlp
  67.  
  68.      Now you can invoke the compiler with a command like `gcc /verbose
  69.      file.c', which is equivalent to the command `gcc -v -c file.c' in
  70.      Unix.
  71.  
  72.    If you wish to use GNU C++ you must first install GNU CC, and then
  73. perform the following steps:
  74.  
  75.   1. Define the VMS logical name `GNU_GXX_INCLUDE' to point to the
  76.      directory where the preprocessor will search for the C++ header
  77.      files.  This can be done with the command:
  78.  
  79.           $ assign /system /translation=concealed -
  80.             disk:[gcc.gxx_include.] gnu_gxx_include
  81.  
  82.      with the appropriate disk and directory name.  If you are going to
  83.      be using libg++, this is where the libg++ install procedure will
  84.      install the libg++ header files.
  85.  
  86.   2. Obtain the file `gcc-cc1plus.exe', and place this in the same
  87.      directory that `gcc-cc1.exe' is kept.
  88.  
  89.      The GNU C++ compiler can be invoked with a command like `gcc /plus
  90.      /verbose file.cc', which is equivalent to the command `g++ -v -c
  91.      file.cc' in Unix.
  92.  
  93.    We try to put corresponding binaries and sources on the VMS
  94. distribution tape.  But sometimes the binaries will be from an older
  95. version than the sources, because we don't always have time to update
  96. them.  (Use the `/version' option to determine the version number of
  97. the binaries and compare it with the source file `version.c' to tell
  98. whether this is so.)  In this case, you should use the binaries you get
  99. to recompile the sources.  If you must recompile, here is how:
  100.  
  101.   1. Execute the command procedure `vmsconfig.com' to set up the files
  102.      `tm.h', `config.h', `aux-output.c', and `md.', and to create files
  103.      `tconfig.h' and `hconfig.h'.  This procedure also creates several
  104.      linker option files used by `make-cc1.com' and a data file used by
  105.      `make-l2.com'.
  106.  
  107.           $ @vmsconfig.com
  108.  
  109.   2. Setup the logical names and command tables as defined above.  In
  110.      addition, define the VMS logical name `GNU_BISON' to point at the
  111.      to the directories where the Bison executable is kept.  This
  112.      should be done with the command:
  113.  
  114.           $ assign /system /translation=concealed -
  115.             disk:[bison.] gnu_bison
  116.  
  117.      You may, if you choose, use the `INSTALL_BISON.COM' script in the
  118.      `[BISON]' directory.
  119.  
  120.   3. Install the `BISON' command with the command line:
  121.  
  122.           $ set command /table=sys$common:[syslib]dcltables -
  123.             /output=sys$common:[syslib]dcltables -
  124.             gnu_bison:[000000]bison
  125.           $ install replace sys$common:[syslib]dcltables
  126.  
  127.   4. Type `@make-gcc' to recompile everything (alternatively, submit
  128.      the file `make-gcc.com' to a batch queue).  If you wish to build
  129.      the GNU C++ compiler as well as the GNU CC compiler, you must
  130.      first edit `make-gcc.com' and follow the instructions that appear
  131.      in the comments.
  132.  
  133.   5. In order to use GCC, you need a library of functions which GCC
  134.      compiled code will call to perform certain tasks, and these
  135.      functions are defined in the file `libgcc2.c'.  To compile this
  136.      you should use the command procedure `make-l2.com', which will
  137.      generate the library `libgcc2.olb'.  `libgcc2.olb' should be built
  138.      using the compiler built from the same distribution that
  139.      `libgcc2.c' came from, and `make-gcc.com' will automatically do
  140.      all of this for you.
  141.  
  142.      To install the library, use the following commands:
  143.  
  144.           $ library gnu_cc:[000000]gcclib/delete=(new,eprintf)
  145.           $ library gnu_cc:[000000]gcclib/delete=L_*
  146.           $ library libgcc2/extract=*/output=libgcc2.obj
  147.           $ library gnu_cc:[000000]gcclib libgcc2.obj
  148.  
  149.      The first command simply removes old modules that will be replaced
  150.      with modules from `libgcc2' under different module names.  The
  151.      modules `new' and `eprintf' may not actually be present in your
  152.      `gcclib.olb'--if the VMS librarian complains about those modules
  153.      not being present, simply ignore the message and continue on with
  154.      the next command.  The second command removes the modules that
  155.      came from the previous version of the library `libgcc2.c'.
  156.  
  157.      Whenever you update the compiler on your system, you should also
  158.      update the library with the above procedure.
  159.  
  160.   6. You may wish to build GCC in such a way that no files are written
  161.      to the directory where the source files reside.  An example would
  162.      be the when the source files are on a read-only disk.  In these
  163.      cases, execute the following DCL commands (substituting your
  164.      actual path names):
  165.  
  166.           $ assign dua0:[gcc.build_dir.]/translation=concealed, -
  167.                    dua1:[gcc.source_dir.]/translation=concealed  gcc_build
  168.           $ set default gcc_build:[000000]
  169.  
  170.      where the directory `dua1:[gcc.source_dir]' contains the source
  171.      code, and the directory `dua0:[gcc.build_dir]' is meant to contain
  172.      all of the generated object files and executables.  Once you have
  173.      done this, you can proceed building GCC as described above.  (Keep
  174.      in mind that `gcc_build' is a rooted logical name, and thus the
  175.      device names in each element of the search list must be an actual
  176.      physical device name rather than another rooted logical name).
  177.  
  178.   7. *If you are building GNU CC with a previous version of GNU CC, you
  179.      also should check to see that you have the newest version of the
  180.      assembler*.  In particular, GNU CC version 2 treats global constant
  181.      variables slightly differently from GNU CC version 1, and GAS
  182.      version 1.38.1 does not have the patches required to work with GCC
  183.      version 2.  If you use GAS 1.38.1, then `extern const' variables
  184.      will not have the read-only bit set, and the linker will generate
  185.      warning messages about mismatched psect attributes for these
  186.      variables.  These warning messages are merely a nuisance, and can
  187.      safely be ignored.
  188.  
  189.      If you are compiling with a version of GNU CC older than 1.33,
  190.      specify `/DEFINE=("inline=")' as an option in all the
  191.      compilations.  This requires editing all the `gcc' commands in
  192.      `make-cc1.com'.  (The older versions had problems supporting
  193.      `inline'.)  Once you have a working 1.33 or newer GNU CC, you can
  194.      change this file back.
  195.  
  196.   8. If you want to build GNU CC with the VAX C compiler, you will need
  197.      to make minor changes in `make-cccp.com' and `make-cc1.com' to
  198.      choose alternate definitions of `CC', `CFLAGS', and `LIBS'.  See
  199.      comments in those files.  However, you must also have a working
  200.      version of the GNU assembler (GNU as, aka GAS) as it is used as
  201.      the back-end for GNU CC to produce binary object modules and is
  202.      not included in the GNU CC sources.  GAS is also needed to compile
  203.      `libgcc2' in order to build `gcclib' (see above); `make-l2.com'
  204.      expects to be able to find it operational in
  205.      `gnu_cc:[000000]gnu-as.exe'.
  206.  
  207.      To use GNU CC on VMS, you need the VMS driver programs `gcc.exe',
  208.      `gcc.com', and `gcc.cld'.  They are distributed with the VMS
  209.      binaries (`gcc-vms') rather than the GNU CC sources.  GAS is also
  210.      included in `gcc-vms', as is Bison.
  211.  
  212.      Once you have successfully built GNU CC with VAX C, you should use
  213.      the resulting compiler to rebuild itself.  Before doing this, be
  214.      sure to restore the `CC', `CFLAGS', and `LIBS' definitions in
  215.      `make-cccp.com' and `make-cc1.com'.  The second generation
  216.      compiler will be able to take advantage of many optimizations that
  217.      must be suppressed when building with other compilers.
  218.  
  219.    Under previous versions of GNU CC, the generated code would
  220. occasionally give strange results when linked with the sharable
  221. `VAXCRTL' library.  Now this should work.
  222.  
  223.    Even with this version, however, GNU CC itself should not be linked
  224. with the sharable `VAXCRTL'.  The version of `qsort' in `VAXCRTL' has a
  225. bug (known to be present in VMS versions V4.6 through V5.5) which
  226. causes the compiler to fail.
  227.  
  228.    The executables are generated by `make-cc1.com' and `make-cccp.com'
  229. use the object library version of `VAXCRTL' in order to make use of the
  230. `qsort' routine in `gcclib.olb'.  If you wish to link the compiler
  231. executables with the shareable image version of `VAXCRTL', you should
  232. edit the file `tm.h' (created by `vmsconfig.com') to define the macro
  233. `QSORT_WORKAROUND'.
  234.  
  235.    `QSORT_WORKAROUND' is always defined when GNU CC is compiled with
  236. VAX C, to avoid a problem in case `gcclib.olb' is not yet available.
  237.  
  238. 
  239. File: gcc.info,  Node: Collect2,  Next: Header Dirs,  Prev: VMS Install,  Up: Installation
  240.  
  241. `collect2'
  242. ==========
  243.  
  244.    Many target systems do not have support in the assembler and linker
  245. for "constructors"--initialization functions to be called before the
  246. official "start" of `main'.  On such systems, GNU CC uses a utility
  247. called `collect2' to arrange to call these functions at start time.
  248.  
  249.    The program `collect2' works by linking the program once and looking
  250. through the linker output file for symbols with particular names
  251. indicating they are constructor functions.  If it finds any, it creates
  252. a new temporary `.c' file containing a table of them, compiles it, and
  253. links the program a second time including that file.
  254.  
  255.    The actual calls to the constructors are carried out by a subroutine
  256. called `__main', which is called (automatically) at the beginning of
  257. the body of `main' (provided `main' was compiled with GNU CC).  Calling
  258. `__main' is necessary, even when compiling C code, to allow linking C
  259. and C++ object code together.  (If you use `-nostdlib', you get an
  260. unresolved reference to `__main', since it's defined in the standard
  261. GCC library.  Include `-lgcc' at the end of your compiler command line
  262. to resolve this reference.)
  263.  
  264.    The program `collect2' is installed as `ld' in the directory where
  265. the passes of the compiler are installed.  When `collect2' needs to
  266. find the *real* `ld', it tries the following file names:
  267.  
  268.    * `real-ld' in the directories listed in the compiler's search
  269.      directories.
  270.  
  271.    * `real-ld' in the directories listed in the environment variable
  272.      `PATH'.
  273.  
  274.    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
  275.      if specified.
  276.  
  277.    * `ld' in the compiler's search directories, except that `collect2'
  278.      will not execute itself recursively.
  279.  
  280.    * `ld' in `PATH'.
  281.  
  282.    "The compiler's search directories" means all the directories where
  283. `gcc' searches for passes of the compiler.  This includes directories
  284. that you specify with `-B'.
  285.  
  286.    Cross-compilers search a little differently:
  287.  
  288.    * `real-ld' in the compiler's search directories.
  289.  
  290.    * `TARGET-real-ld' in `PATH'.
  291.  
  292.    * The file specified in the `REAL_LD_FILE_NAME' configuration macro,
  293.      if specified.
  294.  
  295.    * `ld' in the compiler's search directories.
  296.  
  297.    * `TARGET-ld' in `PATH'.
  298.  
  299.    `collect2' explicitly avoids running `ld' using the file name under
  300. which `collect2' itself was invoked.  In fact, it remembers up a list
  301. of such names--in case one copy of `collect2' finds another copy (or
  302. version) of `collect2' installed as `ld' in a second place in the
  303. search path.
  304.  
  305.    `collect2' searches for the utilities `nm' and `strip' using the
  306. same algorithm as above for `ld'.
  307.  
  308. 
  309. File: gcc.info,  Node: Header Dirs,  Prev: Collect2,  Up: Installation
  310.  
  311. Standard Header File Directories
  312. ================================
  313.  
  314.    `GCC_INCLUDE_DIR' means the same thing for native and cross.  It is
  315. where GNU CC stores its private include files, and also where GNU CC
  316. stores the fixed include files.  A cross compiled GNU CC runs
  317. `fixincludes' on the header files in `$(tooldir)/include'.  (If the
  318. cross compilation header files need to be fixed, they must be installed
  319. before GNU CC is built.  If the cross compilation header files are
  320. already suitable for ANSI C and GNU CC, nothing special need be done).
  321.  
  322.    `GPLUS_INCLUDE_DIR' means the same thing for native and cross.  It
  323. is where `g++' looks first for header files.  `libg++' installs only
  324. target independent header files in that directory.
  325.  
  326.    `LOCAL_INCLUDE_DIR' is used only for a native compiler.  It is
  327. normally `/usr/local/include'.  GNU CC searches this directory so that
  328. users can install header files in `/usr/local/include'.
  329.  
  330.    `CROSS_INCLUDE_DIR' is used only for a cross compiler.  GNU CC
  331. doesn't install anything there.
  332.  
  333.    `TOOL_INCLUDE_DIR' is used for both native and cross compilers.  It
  334. is the place for other packages to install header files that GNU CC will
  335. use.  For a cross-compiler, this is the equivalent of `/usr/include'.
  336. When you build a cross-compiler, `fixincludes' processes any header
  337. files in this directory.
  338.  
  339. 
  340. File: gcc.info,  Node: C Extensions,  Next: C++ Extensions,  Prev: Installation,  Up: Top
  341.  
  342. Extensions to the C Language Family
  343. ***********************************
  344.  
  345.    GNU C provides several language features not found in ANSI standard
  346. C.  (The `-pedantic' option directs GNU CC to print a warning message if
  347. any of these features is used.)  To test for the availability of these
  348. features in conditional compilation, check for a predefined macro
  349. `__GNUC__', which is always defined under GNU CC.
  350.  
  351.    These extensions are available in C and in the languages derived from
  352. it, C++ and Objective C.  *Note Extensions to the C++ Language: C++
  353. Extensions, for extensions that apply *only* to C++.
  354.  
  355. * Menu:
  356.  
  357. * Statement Exprs::     Putting statements and declarations inside expressions.
  358. * Local Labels::        Labels local to a statement-expression.
  359. * Labels as Values::    Getting pointers to labels, and computed gotos.
  360. * Nested Functions::    As in Algol and Pascal, lexical scoping of functions.
  361. * Constructing Calls::    Dispatching a call to another function.
  362. * Naming Types::        Giving a name to the type of some expression.
  363. * Typeof::              `typeof': referring to the type of an expression.
  364. * Lvalues::             Using `?:', `,' and casts in lvalues.
  365. * Conditionals::        Omitting the middle operand of a `?:' expression.
  366. * Long Long::        Double-word integers--`long long int'.
  367. * Complex::             Data types for complex numbers.
  368. * Zero Length::         Zero-length arrays.
  369. * Variable Length::     Arrays whose length is computed at run time.
  370. * Macro Varargs::    Macros with variable number of arguments.
  371. * Subscripting::        Any array can be subscripted, even if not an lvalue.
  372. * Pointer Arith::       Arithmetic on `void'-pointers and function pointers.
  373. * Initializers::        Non-constant initializers.
  374. * Constructors::        Constructor expressions give structures, unions
  375.                          or arrays as values.
  376. * Labeled Elements::    Labeling elements of initializers.
  377. * Cast to Union::       Casting to union type from any member of the union.
  378. * Case Ranges::        `case 1 ... 9' and such.
  379. * Function Attributes:: Declaring that functions have no side effects,
  380.                          or that they can never return.
  381. * Function Prototypes:: Prototype declarations and old-style definitions.
  382. * Dollar Signs::        Dollar sign is allowed in identifiers.
  383. * Character Escapes::   `\e' stands for the character ESC.
  384. * Variable Attributes::    Specifying attributes of variables.
  385. * Alignment::           Inquiring about the alignment of a type or variable.
  386. * Inline::              Defining inline functions (as fast as macros).
  387. * Extended Asm::        Assembler instructions with C expressions as operands.
  388.                          (With them you can define "built-in" functions.)
  389. * Asm Labels::          Specifying the assembler name to use for a C symbol.
  390. * Explicit Reg Vars::   Defining variables residing in specified registers.
  391. * Alternate Keywords::  `__const__', `__asm__', etc., for header files.
  392. * Incomplete Enums::    `enum foo;', with details to follow.
  393. * Function Names::    Printable strings which are the name of the current
  394.              function.
  395.  
  396. 
  397. File: gcc.info,  Node: Statement Exprs,  Next: Local Labels,  Up: C Extensions
  398.  
  399. Statements and Declarations in Expressions
  400. ==========================================
  401.  
  402.    A compound statement enclosed in parentheses may appear as an
  403. expression in GNU C.  This allows you to use loops, switches, and local
  404. variables within an expression.
  405.  
  406.    Recall that a compound statement is a sequence of statements
  407. surrounded by braces; in this construct, parentheses go around the
  408. braces.  For example:
  409.  
  410.      ({ int y = foo (); int z;
  411.         if (y > 0) z = y;
  412.         else z = - y;
  413.         z; })
  414.  
  415. is a valid (though slightly more complex than necessary) expression for
  416. the absolute value of `foo ()'.
  417.  
  418.    The last thing in the compound statement should be an expression
  419. followed by a semicolon; the value of this subexpression serves as the
  420. value of the entire construct.  (If you use some other kind of statement
  421. last within the braces, the construct has type `void', and thus
  422. effectively no value.)
  423.  
  424.    This feature is especially useful in making macro definitions "safe"
  425. (so that they evaluate each operand exactly once).  For example, the
  426. "maximum" function is commonly defined as a macro in standard C as
  427. follows:
  428.  
  429.      #define max(a,b) ((a) > (b) ? (a) : (b))
  430.  
  431. But this definition computes either A or B twice, with bad results if
  432. the operand has side effects.  In GNU C, if you know the type of the
  433. operands (here let's assume `int'), you can define the macro safely as
  434. follows:
  435.  
  436.      #define maxint(a,b) \
  437.        ({int _a = (a), _b = (b); _a > _b ? _a : _b; })
  438.  
  439.    Embedded statements are not allowed in constant expressions, such as
  440. the value of an enumeration constant, the width of a bit field, or the
  441. initial value of a static variable.
  442.  
  443.    If you don't know the type of the operand, you can still do this,
  444. but you must use `typeof' (*note Typeof::.) or type naming (*note
  445. Naming Types::.).
  446.  
  447. 
  448. File: gcc.info,  Node: Local Labels,  Next: Labels as Values,  Prev: Statement Exprs,  Up: C Extensions
  449.  
  450. Locally Declared Labels
  451. =======================
  452.  
  453.    Each statement expression is a scope in which "local labels" can be
  454. declared.  A local label is simply an identifier; you can jump to it
  455. with an ordinary `goto' statement, but only from within the statement
  456. expression it belongs to.
  457.  
  458.    A local label declaration looks like this:
  459.  
  460.      __label__ LABEL;
  461.  
  462. or
  463.  
  464.      __label__ LABEL1, LABEL2, ...;
  465.  
  466.    Local label declarations must come at the beginning of the statement
  467. expression, right after the `({', before any ordinary declarations.
  468.  
  469.    The label declaration defines the label *name*, but does not define
  470. the label itself.  You must do this in the usual way, with `LABEL:',
  471. within the statements of the statement expression.
  472.  
  473.    The local label feature is useful because statement expressions are
  474. often used in macros.  If the macro contains nested loops, a `goto' can
  475. be useful for breaking out of them.  However, an ordinary label whose
  476. scope is the whole function cannot be used: if the macro can be
  477. expanded several times in one function, the label will be multiply
  478. defined in that function.  A local label avoids this problem.  For
  479. example:
  480.  
  481.      #define SEARCH(array, target)                     \
  482.      ({                                               \
  483.        __label__ found;                                \
  484.        typeof (target) _SEARCH_target = (target);      \
  485.        typeof (*(array)) *_SEARCH_array = (array);     \
  486.        int i, j;                                       \
  487.        int value;                                      \
  488.        for (i = 0; i < max; i++)                       \
  489.          for (j = 0; j < max; j++)                     \
  490.            if (_SEARCH_array[i][j] == _SEARCH_target)  \
  491.              { value = i; goto found; }              \
  492.        value = -1;                                     \
  493.       found:                                           \
  494.        value;                                          \
  495.      })
  496.  
  497. 
  498. File: gcc.info,  Node: Labels as Values,  Next: Nested Functions,  Prev: Local Labels,  Up: C Extensions
  499.  
  500. Labels as Values
  501. ================
  502.  
  503.    You can get the address of a label defined in the current function
  504. (or a containing function) with the unary operator `&&'.  The value has
  505. type `void *'.  This value is a constant and can be used wherever a
  506. constant of that type is valid.  For example:
  507.  
  508.      void *ptr;
  509.      ...
  510.      ptr = &&foo;
  511.  
  512.    To use these values, you need to be able to jump to one.  This is
  513. done with the computed goto statement(1), `goto *EXP;'.  For example,
  514.  
  515.      goto *ptr;
  516.  
  517. Any expression of type `void *' is allowed.
  518.  
  519.    One way of using these constants is in initializing a static array
  520. that will serve as a jump table:
  521.  
  522.      static void *array[] = { &&foo, &&bar, &&hack };
  523.  
  524.    Then you can select a label with indexing, like this:
  525.  
  526.      goto *array[i];
  527.  
  528. Note that this does not check whether the subscript is in bounds--array
  529. indexing in C never does that.
  530.  
  531.    Such an array of label values serves a purpose much like that of the
  532. `switch' statement.  The `switch' statement is cleaner, so use that
  533. rather than an array unless the problem does not fit a `switch'
  534. statement very well.
  535.  
  536.    Another use of label values is in an interpreter for threaded code.
  537. The labels within the interpreter function can be stored in the
  538. threaded code for super-fast dispatching.
  539.  
  540.    You can use this mechanism to jump to code in a different function.
  541. If you do that, totally unpredictable things will happen.  The best way
  542. to avoid this is to store the label address only in automatic variables
  543. and never pass it as an argument.
  544.  
  545.    ---------- Footnotes ----------
  546.  
  547.    (1)  The analogous feature in Fortran is called an assigned goto,
  548. but that name seems inappropriate in C, where one can do more than
  549. simply store label addresses in label variables.
  550.  
  551. 
  552. File: gcc.info,  Node: Nested Functions,  Next: Constructing Calls,  Prev: Labels as Values,  Up: C Extensions
  553.  
  554. Nested Functions
  555. ================
  556.  
  557.    A "nested function" is a function defined inside another function.
  558. (Nested functions are not supported for GNU C++.)  The nested function's
  559. name is local to the block where it is defined.  For example, here we
  560. define a nested function named `square', and call it twice:
  561.  
  562.      foo (double a, double b)
  563.      {
  564.        double square (double z) { return z * z; }
  565.      
  566.        return square (a) + square (b);
  567.      }
  568.  
  569.    The nested function can access all the variables of the containing
  570. function that are visible at the point of its definition.  This is
  571. called "lexical scoping".  For example, here we show a nested function
  572. which uses an inherited variable named `offset':
  573.  
  574.      bar (int *array, int offset, int size)
  575.      {
  576.        int access (int *array, int index)
  577.          { return array[index + offset]; }
  578.        int i;
  579.        ...
  580.        for (i = 0; i < size; i++)
  581.          ... access (array, i) ...
  582.      }
  583.  
  584.    Nested function definitions are permitted within functions in the
  585. places where variable definitions are allowed; that is, in any block,
  586. before the first statement in the block.
  587.  
  588.    It is possible to call the nested function from outside the scope of
  589. its name by storing its address or passing the address to another
  590. function:
  591.  
  592.      hack (int *array, int size)
  593.      {
  594.        void store (int index, int value)
  595.          { array[index] = value; }
  596.      
  597.        intermediate (store, size);
  598.      }
  599.  
  600.    Here, the function `intermediate' receives the address of `store' as
  601. an argument.  If `intermediate' calls `store', the arguments given to
  602. `store' are used to store into `array'.  But this technique works only
  603. so long as the containing function (`hack', in this example) does not
  604. exit.
  605.  
  606.    If you try to call the nested function through its address after the
  607. containing function has exited, all hell will break loose.  If you try
  608. to call it after a containing scope level has exited, and if it refers
  609. to some of the variables that are no longer in scope, you may be lucky,
  610. but it's not wise to take the risk.  If, however, the nested function
  611. does not refer to anything that has gone out of scope, you should be
  612. safe.
  613.  
  614.    GNU CC implements taking the address of a nested function using a
  615. technique called "trampolines".  A paper describing them is available
  616. from `maya.idiap.ch' in directory `pub/tmb', file `usenix88-lexic.ps.Z'.
  617.  
  618.    A nested function can jump to a label inherited from a containing
  619. function, provided the label was explicitly declared in the containing
  620. function (*note Local Labels::.).  Such a jump returns instantly to the
  621. containing function, exiting the nested function which did the `goto'
  622. and any intermediate functions as well.  Here is an example:
  623.  
  624.      bar (int *array, int offset, int size)
  625.      {
  626.        __label__ failure;
  627.        int access (int *array, int index)
  628.          {
  629.            if (index > size)
  630.              goto failure;
  631.            return array[index + offset];
  632.          }
  633.        int i;
  634.        ...
  635.        for (i = 0; i < size; i++)
  636.          ... access (array, i) ...
  637.        ...
  638.        return 0;
  639.      
  640.       /* Control comes here from `access'
  641.          if it detects an error.  */
  642.       failure:
  643.        return -1;
  644.      }
  645.  
  646.    A nested function always has internal linkage.  Declaring one with
  647. `extern' is erroneous.  If you need to declare the nested function
  648. before its definition, use `auto' (which is otherwise meaningless for
  649. function declarations).
  650.  
  651.      bar (int *array, int offset, int size)
  652.      {
  653.        __label__ failure;
  654.        auto int access (int *, int);
  655.        ...
  656.        int access (int *array, int index)
  657.          {
  658.            if (index > size)
  659.              goto failure;
  660.            return array[index + offset];
  661.          }
  662.        ...
  663.      }
  664.  
  665. 
  666. File: gcc.info,  Node: Constructing Calls,  Next: Naming Types,  Prev: Nested Functions,  Up: C Extensions
  667.  
  668. Constructing Function Calls
  669. ===========================
  670.  
  671.    Using the built-in functions described below, you can record the
  672. arguments a function received, and call another function with the same
  673. arguments, without knowing the number or types of the arguments.
  674.  
  675.    You can also record the return value of that function call, and
  676. later return that value, without knowing what data type the function
  677. tried to return (as long as your caller expects that data type).
  678.  
  679. `__builtin_apply_args ()'
  680.      This built-in function returns a pointer of type `void *' to data
  681.      describing how to perform a call with the same arguments as were
  682.      passed to the current function.
  683.  
  684.      The function saves the arg pointer register, structure value
  685.      address, and all registers that might be used to pass arguments to
  686.      a function into a block of memory allocated on the stack.  Then it
  687.      returns the address of that block.
  688.  
  689. `__builtin_apply (FUNCTION, ARGUMENTS, SIZE)'
  690.      This built-in function invokes FUNCTION (type `void (*)()') with a
  691.      copy of the parameters described by ARGUMENTS (type `void *') and
  692.      SIZE (type `int').
  693.  
  694.      The value of ARGUMENTS should be the value returned by
  695.      `__builtin_apply_args'.  The argument SIZE specifies the size of
  696.      the stack argument data, in bytes.
  697.  
  698.      This function returns a pointer of type `void *' to data describing
  699.      how to return whatever value was returned by FUNCTION.  The data
  700.      is saved in a block of memory allocated on the stack.
  701.  
  702.      It is not always simple to compute the proper value for SIZE.  The
  703.      value is used by `__builtin_apply' to compute the amount of data
  704.      that should be pushed on the stack and copied from the incoming
  705.      argument area.
  706.  
  707. `__builtin_return (RESULT)'
  708.      This built-in function returns the value described by RESULT from
  709.      the containing function.  You should specify, for RESULT, a value
  710.      returned by `__builtin_apply'.
  711.  
  712. 
  713. File: gcc.info,  Node: Naming Types,  Next: Typeof,  Prev: Constructing Calls,  Up: C Extensions
  714.  
  715. Naming an Expression's Type
  716. ===========================
  717.  
  718.    You can give a name to the type of an expression using a `typedef'
  719. declaration with an initializer.  Here is how to define NAME as a type
  720. name for the type of EXP:
  721.  
  722.      typedef NAME = EXP;
  723.  
  724.    This is useful in conjunction with the statements-within-expressions
  725. feature.  Here is how the two together can be used to define a safe
  726. "maximum" macro that operates on any arithmetic type:
  727.  
  728.      #define max(a,b) \
  729.        ({typedef _ta = (a), _tb = (b);  \
  730.          _ta _a = (a); _tb _b = (b);     \
  731.          _a > _b ? _a : _b; })
  732.  
  733.    The reason for using names that start with underscores for the local
  734. variables is to avoid conflicts with variable names that occur within
  735. the expressions that are substituted for `a' and `b'.  Eventually we
  736. hope to design a new form of declaration syntax that allows you to
  737. declare variables whose scopes start only after their initializers;
  738. this will be a more reliable way to prevent such conflicts.
  739.  
  740. 
  741. File: gcc.info,  Node: Typeof,  Next: Lvalues,  Prev: Naming Types,  Up: C Extensions
  742.  
  743. Referring to a Type with `typeof'
  744. =================================
  745.  
  746.    Another way to refer to the type of an expression is with `typeof'.
  747. The syntax of using of this keyword looks like `sizeof', but the
  748. construct acts semantically like a type name defined with `typedef'.
  749.  
  750.    There are two ways of writing the argument to `typeof': with an
  751. expression or with a type.  Here is an example with an expression:
  752.  
  753.      typeof (x[0](1))
  754.  
  755. This assumes that `x' is an array of functions; the type described is
  756. that of the values of the functions.
  757.  
  758.    Here is an example with a typename as the argument:
  759.  
  760.      typeof (int *)
  761.  
  762. Here the type described is that of pointers to `int'.
  763.  
  764.    If you are writing a header file that must work when included in
  765. ANSI C programs, write `__typeof__' instead of `typeof'.  *Note
  766. Alternate Keywords::.
  767.  
  768.    A `typeof'-construct can be used anywhere a typedef name could be
  769. used.  For example, you can use it in a declaration, in a cast, or
  770. inside of `sizeof' or `typeof'.
  771.  
  772.    * This declares `y' with the type of what `x' points to.
  773.  
  774.           typeof (*x) y;
  775.  
  776.    * This declares `y' as an array of such values.
  777.  
  778.           typeof (*x) y[4];
  779.  
  780.    * This declares `y' as an array of pointers to characters:
  781.  
  782.           typeof (typeof (char *)[4]) y;
  783.  
  784.      It is equivalent to the following traditional C declaration:
  785.  
  786.           char *y[4];
  787.  
  788.      To see the meaning of the declaration using `typeof', and why it
  789.      might be a useful way to write, let's rewrite it with these macros:
  790.  
  791.           #define pointer(T)  typeof(T *)
  792.           #define array(T, N) typeof(T [N])
  793.  
  794.      Now the declaration can be rewritten this way:
  795.  
  796.           array (pointer (char), 4) y;
  797.  
  798.      Thus, `array (pointer (char), 4)' is the type of arrays of 4
  799.      pointers to `char'.
  800.  
  801. 
  802. File: gcc.info,  Node: Lvalues,  Next: Conditionals,  Prev: Typeof,  Up: C Extensions
  803.  
  804. Generalized Lvalues
  805. ===================
  806.  
  807.    Compound expressions, conditional expressions and casts are allowed
  808. as lvalues provided their operands are lvalues.  This means that you
  809. can take their addresses or store values into them.
  810.  
  811.    For example, a compound expression can be assigned, provided the last
  812. expression in the sequence is an lvalue.  These two expressions are
  813. equivalent:
  814.  
  815.      (a, b) += 5
  816.      a, (b += 5)
  817.  
  818.    Similarly, the address of the compound expression can be taken.
  819. These two expressions are equivalent:
  820.  
  821.      &(a, b)
  822.      a, &b
  823.  
  824.    A conditional expression is a valid lvalue if its type is not void
  825. and the true and false branches are both valid lvalues.  For example,
  826. these two expressions are equivalent:
  827.  
  828.      (a ? b : c) = 5
  829.      (a ? b = 5 : (c = 5))
  830.  
  831.    A cast is a valid lvalue if its operand is an lvalue.  A simple
  832. assignment whose left-hand side is a cast works by converting the
  833. right-hand side first to the specified type, then to the type of the
  834. inner left-hand side expression.  After this is stored, the value is
  835. converted back to the specified type to become the value of the
  836. assignment.  Thus, if `a' has type `char *', the following two
  837. expressions are equivalent:
  838.  
  839.      (int)a = 5
  840.      (int)(a = (char *)(int)5)
  841.  
  842.    An assignment-with-arithmetic operation such as `+=' applied to a
  843. cast performs the arithmetic using the type resulting from the cast,
  844. and then continues as in the previous case.  Therefore, these two
  845. expressions are equivalent:
  846.  
  847.      (int)a += 5
  848.      (int)(a = (char *)(int) ((int)a + 5))
  849.  
  850.    You cannot take the address of an lvalue cast, because the use of its
  851. address would not work out coherently.  Suppose that `&(int)f' were
  852. permitted, where `f' has type `float'.  Then the following statement
  853. would try to store an integer bit-pattern where a floating point number
  854. belongs:
  855.  
  856.      *&(int)f = 1;
  857.  
  858.    This is quite different from what `(int)f = 1' would do--that would
  859. convert 1 to floating point and store it.  Rather than cause this
  860. inconsistency, we think it is better to prohibit use of `&' on a cast.
  861.  
  862.    If you really do want an `int *' pointer with the address of `f',
  863. you can simply write `(int *)&f'.
  864.  
  865. 
  866. File: gcc.info,  Node: Conditionals,  Next: Long Long,  Prev: Lvalues,  Up: C Extensions
  867.  
  868. Conditionals with Omitted Operands
  869. ==================================
  870.  
  871.    The middle operand in a conditional expression may be omitted.  Then
  872. if the first operand is nonzero, its value is the value of the
  873. conditional expression.
  874.  
  875.    Therefore, the expression
  876.  
  877.      x ? : y
  878.  
  879. has the value of `x' if that is nonzero; otherwise, the value of `y'.
  880.  
  881.    This example is perfectly equivalent to
  882.  
  883.      x ? x : y
  884.  
  885. In this simple case, the ability to omit the middle operand is not
  886. especially useful.  When it becomes useful is when the first operand
  887. does, or may (if it is a macro argument), contain a side effect.  Then
  888. repeating the operand in the middle would perform the side effect
  889. twice.  Omitting the middle operand uses the value already computed
  890. without the undesirable effects of recomputing it.
  891.  
  892. 
  893. File: gcc.info,  Node: Long Long,  Next: Complex,  Prev: Conditionals,  Up: C Extensions
  894.  
  895. Double-Word Integers
  896. ====================
  897.  
  898.    GNU C supports data types for integers that are twice as long as
  899. `long int'.  Simply write `long long int' for a signed integer, or
  900. `unsigned long long int' for an unsigned integer.  To make an integer
  901. constant of type `long long int', add the suffix `LL' to the integer.
  902. To make an integer constant of type `unsigned long long int', add the
  903. suffix `ULL' to the integer.
  904.  
  905.    You can use these types in arithmetic like any other integer types.
  906. Addition, subtraction, and bitwise boolean operations on these types
  907. are open-coded on all types of machines.  Multiplication is open-coded
  908. if the machine supports fullword-to-doubleword a widening multiply
  909. instruction.  Division and shifts are open-coded only on machines that
  910. provide special support.  The operations that are not open-coded use
  911. special library routines that come with GNU CC.
  912.  
  913.    There may be pitfalls when you use `long long' types for function
  914. arguments, unless you declare function prototypes.  If a function
  915. expects type `int' for its argument, and you pass a value of type `long
  916. long int', confusion will result because the caller and the subroutine
  917. will disagree about the number of bytes for the argument.  Likewise, if
  918. the function expects `long long int' and you pass `int'.  The best way
  919. to avoid such problems is to use prototypes.
  920.  
  921. 
  922. File: gcc.info,  Node: Complex,  Next: Zero Length,  Prev: Long Long,  Up: C Extensions
  923.  
  924. Complex Numbers
  925. ===============
  926.  
  927.    GNU C supports complex data types.  You can declare both complex
  928. integer types and complex floating types, using the keyword
  929. `__complex__'.
  930.  
  931.    For example, `__complex__ double x;' declares `x' as a variable
  932. whose real part and imaginary part are both of type `double'.
  933. `__complex__ short int y;' declares `y' to have real and imaginary
  934. parts of type `short int'; this is not likely to be useful, but it
  935. shows that the set of complex types is complete.
  936.  
  937.    To write a constant with a complex data type, use the suffix `i' or
  938. `j' (either one; they are equivalent).  For example, `2.5fi' has type
  939. `__complex__ float' and `3i' has type `__complex__ int'.  Such a
  940. constant always has a pure imaginary value, but you can form any
  941. complex value you like by adding one to a real constant.
  942.  
  943.    To extract the real part of a complex-valued expression EXP, write
  944. `__real__ EXP'.  Likewise, use `__imag__' to extract the imaginary part.
  945.  
  946.    The operator `~' performs complex conjugation when used on a value
  947. with a complex type.
  948.  
  949.    GNU CC can allocate complex automatic variables in a noncontiguous
  950. fashion; it's even possible for the real part to be in a register while
  951. the imaginary part is on the stack (or vice-versa).  None of the
  952. supported debugging info formats has a way to represent noncontiguous
  953. allocation like this, so GNU CC describes a noncontiguous complex
  954. variable as if it were two separate variables of noncomplex type.  If
  955. the variable's actual name is `foo', the two fictitious variables are
  956. named `foo$real' and `foo$imag'.  You can examine and set these two
  957. fictitious variables with your debugger.
  958.  
  959.    A future version of GDB will know how to recognize such pairs and
  960. treat them as a single variable with a complex type.
  961.  
  962. 
  963. File: gcc.info,  Node: Zero Length,  Next: Variable Length,  Prev: Complex,  Up: C Extensions
  964.  
  965. Arrays of Length Zero
  966. =====================
  967.  
  968.    Zero-length arrays are allowed in GNU C.  They are very useful as
  969. the last element of a structure which is really a header for a
  970. variable-length object:
  971.  
  972.      struct line {
  973.        int length;
  974.        char contents[0];
  975.      };
  976.      
  977.      {
  978.        struct line *thisline = (struct line *)
  979.          malloc (sizeof (struct line) + this_length);
  980.        thisline->length = this_length;
  981.      }
  982.  
  983.    In standard C, you would have to give `contents' a length of 1, which
  984. means either you waste space or complicate the argument to `malloc'.
  985.  
  986. 
  987. File: gcc.info,  Node: Variable Length,  Next: Macro Varargs,  Prev: Zero Length,  Up: C Extensions
  988.  
  989. Arrays of Variable Length
  990. =========================
  991.  
  992.    Variable-length automatic arrays are allowed in GNU C.  These arrays
  993. are declared like any other automatic arrays, but with a length that is
  994. not a constant expression.  The storage is allocated at the point of
  995. declaration and deallocated when the brace-level is exited.  For
  996. example:
  997.  
  998.      FILE *
  999.      concat_fopen (char *s1, char *s2, char *mode)
  1000.      {
  1001.        char str[strlen (s1) + strlen (s2) + 1];
  1002.        strcpy (str, s1);
  1003.        strcat (str, s2);
  1004.        return fopen (str, mode);
  1005.      }
  1006.  
  1007.    Jumping or breaking out of the scope of the array name deallocates
  1008. the storage.  Jumping into the scope is not allowed; you get an error
  1009. message for it.
  1010.  
  1011.    You can use the function `alloca' to get an effect much like
  1012. variable-length arrays.  The function `alloca' is available in many
  1013. other C implementations (but not in all).  On the other hand,
  1014. variable-length arrays are more elegant.
  1015.  
  1016.    There are other differences between these two methods.  Space
  1017. allocated with `alloca' exists until the containing *function* returns.
  1018. The space for a variable-length array is deallocated as soon as the
  1019. array name's scope ends.  (If you use both variable-length arrays and
  1020. `alloca' in the same function, deallocation of a variable-length array
  1021. will also deallocate anything more recently allocated with `alloca'.)
  1022.  
  1023.    You can also use variable-length arrays as arguments to functions:
  1024.  
  1025.      struct entry
  1026.      tester (int len, char data[len][len])
  1027.      {
  1028.        ...
  1029.      }
  1030.  
  1031.    The length of an array is computed once when the storage is allocated
  1032. and is remembered for the scope of the array in case you access it with
  1033. `sizeof'.
  1034.  
  1035.    If you want to pass the array first and the length afterward, you can
  1036. use a forward declaration in the parameter list--another GNU extension.
  1037.  
  1038.      struct entry
  1039.      tester (int len; char data[len][len], int len)
  1040.      {
  1041.        ...
  1042.      }
  1043.  
  1044.    The `int len' before the semicolon is a "parameter forward
  1045. declaration", and it serves the purpose of making the name `len' known
  1046. when the declaration of `data' is parsed.
  1047.  
  1048.    You can write any number of such parameter forward declarations in
  1049. the parameter list.  They can be separated by commas or semicolons, but
  1050. the last one must end with a semicolon, which is followed by the "real"
  1051. parameter declarations.  Each forward declaration must match a "real"
  1052. declaration in parameter name and data type.
  1053.  
  1054. 
  1055. File: gcc.info,  Node: Macro Varargs,  Next: Subscripting,  Prev: Variable Length,  Up: C Extensions
  1056.  
  1057. Macros with Variable Numbers of Arguments
  1058. =========================================
  1059.  
  1060.    In GNU C, a macro can accept a variable number of arguments, much as
  1061. a function can.  The syntax for defining the macro looks much like that
  1062. used for a function.  Here is an example:
  1063.  
  1064.      #define eprintf(format, args...)  \
  1065.       fprintf (stderr, format , ## args)
  1066.  
  1067.    Here `args' is a "rest argument": it takes in zero or more
  1068. arguments, as many as the call contains.  All of them plus the commas
  1069. between them form the value of `args', which is substituted into the
  1070. macro body where `args' is used.  Thus, we have this expansion:
  1071.  
  1072.      eprintf ("%s:%d: ", input_file_name, line_number)
  1073.      ==>
  1074.      fprintf (stderr, "%s:%d: " , input_file_name, line_number)
  1075.  
  1076. Note that the comma after the string constant comes from the definition
  1077. of `eprintf', whereas the last comma comes from the value of `args'.
  1078.  
  1079.    The reason for using `##' is to handle the case when `args' matches
  1080. no arguments at all.  In this case, `args' has an empty value.  In this
  1081. case, the second comma in the definition becomes an embarrassment: if
  1082. it got through to the expansion of the macro, we would get something
  1083. like this:
  1084.  
  1085.      fprintf (stderr, "success!\n" , )
  1086.  
  1087. which is invalid C syntax.  `##' gets rid of the comma, so we get the
  1088. following instead:
  1089.  
  1090.      fprintf (stderr, "success!\n")
  1091.  
  1092.    This is a special feature of the GNU C preprocessor: `##' before a
  1093. rest argument that is empty discards the preceding sequence of
  1094. non-whitespace characters from the macro definition.  (If another macro
  1095. argument precedes, none of it is discarded.)
  1096.  
  1097.    It might be better to discard the last preprocessor token instead of
  1098. the last preceding sequence of non-whitespace characters; in fact, we
  1099. may someday change this feature to do so.  We advise you to write the
  1100. macro definition so that the preceding sequence of non-whitespace
  1101. characters is just a single token, so that the meaning will not change
  1102. if we change the definition of this feature.
  1103.  
  1104. 
  1105. File: gcc.info,  Node: Subscripting,  Next: Pointer Arith,  Prev: Macro Varargs,  Up: C Extensions
  1106.  
  1107. Non-Lvalue Arrays May Have Subscripts
  1108. =====================================
  1109.  
  1110.    Subscripting is allowed on arrays that are not lvalues, even though
  1111. the unary `&' operator is not.  For example, this is valid in GNU C
  1112. though not valid in other C dialects:
  1113.  
  1114.      struct foo {int a[4];};
  1115.      
  1116.      struct foo f();
  1117.      
  1118.      bar (int index)
  1119.      {
  1120.        return f().a[index];
  1121.      }
  1122.  
  1123. 
  1124. File: gcc.info,  Node: Pointer Arith,  Next: Initializers,  Prev: Subscripting,  Up: C Extensions
  1125.  
  1126. Arithmetic on `void'- and Function-Pointers
  1127. ===========================================
  1128.  
  1129.    In GNU C, addition and subtraction operations are supported on
  1130. pointers to `void' and on pointers to functions.  This is done by
  1131. treating the size of a `void' or of a function as 1.
  1132.  
  1133.    A consequence of this is that `sizeof' is also allowed on `void' and
  1134. on function types, and returns 1.
  1135.  
  1136.    The option `-Wpointer-arith' requests a warning if these extensions
  1137. are used.
  1138.  
  1139. 
  1140. File: gcc.info,  Node: Initializers,  Next: Constructors,  Prev: Pointer Arith,  Up: C Extensions
  1141.  
  1142. Non-Constant Initializers
  1143. =========================
  1144.  
  1145.    The elements of an aggregate initializer for an automatic variable
  1146. are not required to be constant expressions in GNU C.  Here is an
  1147. example of an initializer with run-time varying elements:
  1148.  
  1149.      foo (float f, float g)
  1150.      {
  1151.        float beat_freqs[2] = { f-g, f+g };
  1152.        ...
  1153.      }
  1154.  
  1155. 
  1156. File: gcc.info,  Node: Constructors,  Next: Labeled Elements,  Prev: Initializers,  Up: C Extensions
  1157.  
  1158. Constructor Expressions
  1159. =======================
  1160.  
  1161.    GNU C supports constructor expressions.  A constructor looks like a
  1162. cast containing an initializer.  Its value is an object of the type
  1163. specified in the cast, containing the elements specified in the
  1164. initializer.
  1165.  
  1166.    Usually, the specified type is a structure.  Assume that `struct
  1167. foo' and `structure' are declared as shown:
  1168.  
  1169.      struct foo {int a; char b[2];} structure;
  1170.  
  1171. Here is an example of constructing a `struct foo' with a constructor:
  1172.  
  1173.      structure = ((struct foo) {x + y, 'a', 0});
  1174.  
  1175. This is equivalent to writing the following:
  1176.  
  1177.      {
  1178.        struct foo temp = {x + y, 'a', 0};
  1179.        structure = temp;
  1180.      }
  1181.  
  1182.    You can also construct an array.  If all the elements of the
  1183. constructor are (made up of) simple constant expressions, suitable for
  1184. use in initializers, then the constructor is an lvalue and can be
  1185. coerced to a pointer to its first element, as shown here:
  1186.  
  1187.      char **foo = (char *[]) { "x", "y", "z" };
  1188.  
  1189.    Array constructors whose elements are not simple constants are not
  1190. very useful, because the constructor is not an lvalue.  There are only
  1191. two valid ways to use it: to subscript it, or initialize an array
  1192. variable with it.  The former is probably slower than a `switch'
  1193. statement, while the latter does the same thing an ordinary C
  1194. initializer would do.  Here is an example of subscripting an array
  1195. constructor:
  1196.  
  1197.      output = ((int[]) { 2, x, 28 }) [input];
  1198.  
  1199.    Constructor expressions for scalar types and union types are is also
  1200. allowed, but then the constructor expression is equivalent to a cast.
  1201.  
  1202. 
  1203. File: gcc.info,  Node: Labeled Elements,  Next: Cast to Union,  Prev: Constructors,  Up: C Extensions
  1204.  
  1205. Labeled Elements in Initializers
  1206. ================================
  1207.  
  1208.    Standard C requires the elements of an initializer to appear in a
  1209. fixed order, the same as the order of the elements in the array or
  1210. structure being initialized.
  1211.  
  1212.    In GNU C you can give the elements in any order, specifying the array
  1213. indices or structure field names they apply to.
  1214.  
  1215.    To specify an array index, write `[INDEX]' or `[INDEX] =' before the
  1216. element value.  For example,
  1217.  
  1218.      int a[6] = { [4] 29, [2] = 15 };
  1219.  
  1220. is equivalent to
  1221.  
  1222.      int a[6] = { 0, 0, 15, 0, 29, 0 };
  1223.  
  1224. The index values must be constant expressions, even if the array being
  1225. initialized is automatic.
  1226.  
  1227.    To initialize a range of elements to the same value, write `[FIRST
  1228. ... LAST] = VALUE'.  For example,
  1229.  
  1230.      int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
  1231.  
  1232. Note that the length of the array is the highest value specified plus
  1233. one.
  1234.  
  1235.    In a structure initializer, specify the name of a field to initialize
  1236. with `FIELDNAME:' before the element value.  For example, given the
  1237. following structure,
  1238.  
  1239.      struct point { int x, y; };
  1240.  
  1241. the following initialization
  1242.  
  1243.      struct point p = { y: yvalue, x: xvalue };
  1244.  
  1245. is equivalent to
  1246.  
  1247.      struct point p = { xvalue, yvalue };
  1248.  
  1249.    Another syntax which has the same meaning is `.FIELDNAME ='., as
  1250. shown here:
  1251.  
  1252.      struct point p = { .y = yvalue, .x = xvalue };
  1253.  
  1254.    You can also use an element label (with either the colon syntax or
  1255. the period-equal syntax) when initializing a union, to specify which
  1256. element of the union should be used.  For example,
  1257.  
  1258.      union foo { int i; double d; };
  1259.      
  1260.      union foo f = { d: 4 };
  1261.  
  1262. will convert 4 to a `double' to store it in the union using the second
  1263. element.  By contrast, casting 4 to type `union foo' would store it
  1264. into the union as the integer `i', since it is an integer.  (*Note Cast
  1265. to Union::.)
  1266.  
  1267.    You can combine this technique of naming elements with ordinary C
  1268. initialization of successive elements.  Each initializer element that
  1269. does not have a label applies to the next consecutive element of the
  1270. array or structure.  For example,
  1271.  
  1272.      int a[6] = { [1] = v1, v2, [4] = v4 };
  1273.  
  1274. is equivalent to
  1275.  
  1276.      int a[6] = { 0, v1, v2, 0, v4, 0 };
  1277.  
  1278.    Labeling the elements of an array initializer is especially useful
  1279. when the indices are characters or belong to an `enum' type.  For
  1280. example:
  1281.  
  1282.      int whitespace[256]
  1283.        = { [' '] = 1, ['\t'] = 1, ['\h'] = 1,
  1284.            ['\f'] = 1, ['\n'] = 1, ['\r'] = 1 };
  1285.  
  1286.