home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gnu / gcc-2.5.8-bin.lha / info / gcc.info-8 (.txt) < prev    next >
GNU Info File  |  1994-07-11  |  51KB  |  897 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 675 Massachusetts Avenue
  5. Cambridge, MA 02139 USA
  6.    Copyright (C) 1988, 1989, 1992, 1993 Free Software Foundation, Inc.
  7.    Permission is granted to make and distribute verbatim copies of this
  8. manual provided the copyright notice and this permission notice are
  9. preserved on all copies.
  10.    Permission is granted to copy and distribute modified versions of
  11. this manual under the conditions for verbatim copying, provided also
  12. that the sections entitled "GNU General Public License" and "Protect
  13. Your Freedom--Fight `Look And Feel'" are included exactly as in the
  14. original, and provided that the entire resulting derived work is
  15. distributed under the terms of a permission notice identical to this
  16.    Permission is granted to copy and distribute translations of this
  17. manual into another language, under the above conditions for modified
  18. versions, except that the sections entitled "GNU General Public
  19. License" and "Protect Your Freedom--Fight `Look And Feel'", and this
  20. permission notice, may be included in translations approved by the Free
  21. Software Foundation instead of in the original English.
  22. File: gcc.info,  Node: Local Reg Vars,  Prev: Global Reg Vars,  Up: Explicit Reg Vars
  23. Specifying Registers for Local Variables
  24. ----------------------------------------
  25.    You can define a local register variable with a specified register
  26. like this:
  27.      register int *foo asm ("a5");
  28. Here `a5' is the name of the register which should be used.  Note that
  29. this is the same syntax used for defining global register variables,
  30. but for a local variable it would appear within a function.
  31.    Naturally the register name is cpu-dependent, but this is not a
  32. problem, since specific registers are most often useful with explicit
  33. assembler instructions (*note Extended Asm::.).  Both of these things
  34. generally require that you conditionalize your program according to cpu
  35. type.
  36.    In addition, operating systems on one type of cpu may differ in how
  37. they name the registers; then you would need additional conditionals.
  38. For example, some 68000 operating systems call this register `%a5'.
  39.    Eventually there may be a way of asking the compiler to choose a
  40. register automatically, but first we need to figure out how it should
  41. choose and how to enable you to guide the choice.  No solution is
  42. evident.
  43.    Defining such a register variable does not reserve the register; it
  44. remains available for other uses in places where flow control determines
  45. the variable's value is not live.  However, these registers are made
  46. unavailable for use in the reload pass.  I would not be surprised if
  47. excessive use of this feature leaves the compiler too few available
  48. registers to compile certain functions.
  49. File: gcc.info,  Node: Alternate Keywords,  Next: Incomplete Enums,  Prev: Explicit Reg Vars,  Up: C Extensions
  50. Alternate Keywords
  51. ==================
  52.    The option `-traditional' disables certain keywords; `-ansi'
  53. disables certain others.  This causes trouble when you want to use GNU C
  54. extensions, or ANSI C features, in a general-purpose header file that
  55. should be usable by all programs, including ANSI C programs and
  56. traditional ones.  The keywords `asm', `typeof' and `inline' cannot be
  57. used since they won't work in a program compiled with `-ansi', while
  58. the keywords `const', `volatile', `signed', `typeof' and `inline' won't
  59. work in a program compiled with `-traditional'.
  60.    The way to solve these problems is to put `__' at the beginning and
  61. end of each problematical keyword.  For example, use `__asm__' instead
  62. of `asm', `__const__' instead of `const', and `__inline__' instead of
  63. `inline'.
  64.    Other C compilers won't accept these alternative keywords; if you
  65. want to compile with another compiler, you can define the alternate
  66. keywords as macros to replace them with the customary keywords.  It
  67. looks like this:
  68.      #ifndef __GNUC__
  69.      #define __asm__ asm
  70.      #endif
  71.    `-pedantic' causes warnings for many GNU C extensions.  You can
  72. prevent such warnings within one expression by writing `__extension__'
  73. before the expression.  `__extension__' has no effect aside from this.
  74. File: gcc.info,  Node: Incomplete Enums,  Next: Function Names,  Prev: Alternate Keywords,  Up: C Extensions
  75. Incomplete `enum' Types
  76. =======================
  77.    You can define an `enum' tag without specifying its possible values.
  78. This results in an incomplete type, much like what you get if you write
  79. `struct foo' without describing the elements.  A later declaration
  80. which does specify the possible values completes the type.
  81.    You can't allocate variables or storage using the type while it is
  82. incomplete.  However, you can work with pointers to that type.
  83.    This extension may not be very useful, but it makes the handling of
  84. `enum' more consistent with the way `struct' and `union' are handled.
  85. File: gcc.info,  Node: Function Names,  Prev: Incomplete Enums,  Up: C Extensions
  86. Function Names as Strings
  87. =========================
  88.    GNU CC predefines two string variables to be the name of the current
  89. function.  The variable `__FUNCTION__' is the name of the function as
  90. it appears in the source.  The variable `__PRETTY_FUNCTION__' is the
  91. name of the function pretty printed in a language specific fashion.
  92.    These names are always the same in a C function, but in a C++
  93. function they may be different.  For example, this program:
  94.      extern "C" {
  95.      extern int printf (char *, ...);
  96.      }
  97.      
  98.      class a {
  99.       public:
  100.        sub (int i)
  101.          {
  102.            printf ("__FUNCTION__ = %s\n", __FUNCTION__);
  103.            printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
  104.          }
  105.      };
  106.      
  107.      int
  108.      main (void)
  109.      {
  110.        a ax;
  111.        ax.sub (0);
  112.        return 0;
  113.      }
  114. gives this output:
  115.      __FUNCTION__ = sub
  116.      __PRETTY_FUNCTION__ = int  a::sub (int)
  117. File: gcc.info,  Node: C++ Extensions,  Next: Trouble,  Prev: C Extensions,  Up: Top
  118. Extensions to the C++ Language
  119. ******************************
  120.    The GNU compiler provides these extensions to the C++ language (and
  121. you can also use most of the C language extensions in your C++
  122. programs).  If you want to write code that checks whether these
  123. features are available, you can test for the GNU compiler the same way
  124. as for C programs: check for a predefined macro `__GNUC__'.  You can
  125. also use `__GNUG__' to test specifically for GNU C++ (*note Standard
  126. Predefined Macros: (cpp.info)Standard Predefined.).
  127. * Menu:
  128. * Naming Results::      Giving a name to C++ function return values.
  129. * Min and Max::        C++ Minimum and maximum operators.
  130. * Destructors and Goto:: Goto is safe to use in C++ even when destructors
  131.                            are needed.
  132. * C++ Interface::       You can use a single C++ header file for both
  133.                          declarations and definitions.
  134. File: gcc.info,  Node: Naming Results,  Next: Min and Max,  Up: C++ Extensions
  135. Named Return Values in C++
  136. ==========================
  137.    GNU C++ extends the function-definition syntax to allow you to
  138. specify a name for the result of a function outside the body of the
  139. definition, in C++ programs:
  140.      TYPE
  141.      FUNCTIONNAME (ARGS) return RESULTNAME;
  142.      {
  143.        ...
  144.        BODY
  145.        ...
  146.      }
  147.    You can use this feature to avoid an extra constructor call when a
  148. function result has a class type.  For example, consider a function
  149. `m', declared as `X v = m ();', whose result is of class `X':
  150.      X
  151.      m ()
  152.      {
  153.        X b;
  154.        b.a = 23;
  155.        return b;
  156.      }
  157.    Although `m' appears to have no arguments, in fact it has one
  158. implicit argument: the address of the return value.  At invocation, the
  159. address of enough space to hold `v' is sent in as the implicit argument.
  160. Then `b' is constructed and its `a' field is set to the value 23.
  161. Finally, a copy constructor (a constructor of the form `X(X&)') is
  162. applied to `b', with the (implicit) return value location as the
  163. target, so that `v' is now bound to the return value.
  164.    But this is wasteful.  The local `b' is declared just to hold
  165. something that will be copied right out.  While a com