home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / gcc-2.7.2.1-base.tgz / gcc-2.7.2.1-base.tar / fsf / gcc / gcc.info-8 (.txt) < prev    next >
GNU Info File  |  1996-06-29  |  50KB  |  920 lines

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