home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / gcc / gcc.info-10 (.txt) < prev    next >
GNU Info File  |  1995-11-26  |  38KB  |  681 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: Asm Labels,  Next: Explicit Reg Vars,  Prev: Extended Asm,  Up: C Extensions
  26. Controlling Names Used in Assembler Code
  27. ========================================
  28.    You can specify the name to be used in the assembler code for a C
  29. function or variable by writing the `asm' (or `__asm__') keyword after
  30. the declarator as follows:
  31.      int foo asm ("myfoo") = 2;
  32. This specifies that the name to be used for the variable `foo' in the
  33. assembler code should be `myfoo' rather than the usual `_foo'.
  34.    On systems where an underscore is normally prepended to the name of
  35. a C function or variable, this feature allows you to define names for
  36. the linker that do not start with an underscore.
  37.    You cannot use `asm' in this way in a function *definition*; but you
  38. can get the same effect by writing a declaration for the function
  39. before its definition and putting `asm' there, like this:
  40.      extern func () asm ("FUNC");
  41.      
  42.      func (x, y)
  43.           int x, y;
  44.      ...
  45.    It is up to you to make sure that the assembler names you choose do
  46. not conflict with any other assembler symbols.  Also, you must not use a
  47. register name; that would produce completely invalid assembler code.
  48. GNU CC does not as yet have the ability to store static variables in
  49. registers.  Perhaps that will be added.
  50. File: gcc.info,  Node: Explicit Reg Vars,  Next: Alternate Keywords,  Prev: Asm Labels,  Up: C Extensions
  51. Variables in Specified Registers
  52. ================================
  53.    GNU C allows you to put a few global variables into specified
  54. hardware registers.  You can also specify the register in which an
  55. ordinary register variable should be allocated.
  56.    * Global register variables reserve registers throughout the program.
  57.      This may be useful in programs such as programming language
  58.      interpreters which have a couple of global variables that are
  59.      accessed very often.
  60.    * Local register variables in specific registers do not reserve the
  61.      registers.  The compiler's data flow analysis is capable of
  62.      determining where the specified registers contain live values, and
  63.      where they are available for other uses.
  64.      These local variables are sometimes convenient for use with the
  65.      extended `asm' feature (*note Extended Asm::.), if you want to
  66.      write one output of the assembler instruction directly into a
  67.      particular register.  (This will work provided the register you
  68.      specify fits the constraints specified for that operand in the
  69.      `asm'.)
  70. * Menu:
  71. * Global Reg Vars::
  72. * Local Reg Vars::
  73. File: gcc.info,  Node: Global Reg Vars,  Next: Local Reg Vars,  Up: Explicit Reg Vars
  74. Defining Global Register Variables
  75. ----------------------------------
  76.    You can define a global register variable in GNU C like this:
  77.      register int *foo asm ("a5");
  78. Here `a5' is the name of the register which should be used.  Choose a
  79. register which is normally saved and restored by function calls on your
  80. machine, so that library routines will not clobber it.
  81.    Naturally the register name is cpu-dependent, so you would need to
  82. conditionalize your program according to cpu type.  The register `a5'
  83. would be a good choice on a 68000 for a variable of pointer type.  On
  84. machines with register windows, be sure to choose a "global" register
  85. that is not affected magically by the function call mechanism.
  86.    In addition, operating systems on one type of cpu may differ in how
  87. they name the registers; then you would need additional conditionals.
  88. For example, some 68000 operating systems call this register `%a5'.
  89.    Eventually there may be a way of asking the compiler to choose a
  90. register automatically, but first we need to figure out how it should
  91. choose and how to enable you to guide the choice.  No solution is
  92. evident.
  93.    Defining a global register variable in a certain register reserves
  94. that register entirely for this use, at least within the current
  95. compilation.  The register will not be allocated for any other purpose
  96. in the functions in the current compilation.  The register will not be
  97. saved and restored by these functions.  Stores into this register are
  98. never deleted even if they would appear to be dead, but references may
  99. be deleted or moved or simplified.
  100.    It is not safe to access the global register variables from signal
  101. handlers, or from more than one thread of control, because the system
  102. library routines may temporarily use the register for other things
  103. (unless you recompile them specially for the task at hand).
  104.    It is not safe for one function that uses a global register variable
  105. to call another such function `foo' by way of a third function `lose'
  106. that was compiled without knowledge of this variable (i.e. in a
  107. different source file in which the variable wasn't declared).  This is
  108. because `lose' might save the register and put some other value there.
  109. For example, you can't expect a global register variable to be
  110. available in the comparison-function that you pass to `qsort', since
  111. `qsort' might have put something else in that register.  (If you are
  112. prepared to recompile `qsort' with the same global register variable,
  113. you can solve this problem.)
  114.    If you want to recompile `qsort' or other source files which do not
  115. actually use your global register variable, so that they will not use
  116. that register for any other purpose, then it suffices to specify the
  117. compiler option `-ffixed-REG'.  You need not actually add a global
  118. register declaration to their source code.
  119.    A function which can alter the value of a global register variable
  120. cannot safely be called from a function compiled without this variable,
  121. because it could clobber the value the caller expects to find there on
  122. return.  Therefore, the function which is the entry point into the part
  123. of the program that uses the global register variable must explicitly
  124. save and restore the value which belongs to its caller.
  125.    On most machines, `longjmp' will restore to each global register
  126. variable the value it had at the time of the `setjmp'.  On some
  127. machines, however, `longjmp' will not change the value of global
  128. register variables.  To be portable, the function that called `setjmp'
  129. should make other arrangements to save the values of the global register
  130. variables, and to restore them in a `longjmp'.  This way, the same
  131. thing will happen regardless of what `longjmp' does.
  132.    All global register variable declarations must precede all function
  133. definitions.  If such a declaration could appear after function
  134. definitions, the declaration would be too late to prevent the register
  135. from being used for other purposes in the preceding functions.
  136.    Global register variables may not have initial values, because an
  137. executable file has no means to supply initial contents for a register.
  138.    On the Sparc, there are reports that g3 ... g7 are suitable
  139. registers, but certain library functions, such as `getwd', as well as
  140. the subroutines for division and remainder, modify g3 and g4.  g1 and
  141. g2 are local temporaries.
  142.    On the 68000, a2 ... a5 should be suitable, as should d2 ... d7.  Of
  143. course, it will not do to use more than a few of those.
  144. File: gcc.info,  Node: Local Reg Vars,  Prev: Global Reg Vars,  Up: Explicit Reg Vars
  145. Specifying Registers for Local Variables
  146. ----------------------------------------
  147.    You can define a local register variable with a specified register
  148. like this:
  149.      register int *foo asm ("a5");
  150. Here `a5' is the name of the register which should be used.  Note that
  151. this is the same syntax used for defining global register variables,
  152. but for a local variable it would appear within a function.
  153.    Naturally the register name is cpu-dependent, but this is not a
  154. problem, since specific registers are most often useful with explicit
  155. assembler instructions (*note Extended Asm::.).  Both of these things
  156. generally require that you conditionalize your program according to cpu
  157. type.
  158.    In addition, operating systems on one type of cpu may differ in how
  159. they name the registers; then you would need additional conditionals.
  160. For example, some 68000 operating systems call this register `%a5'.
  161.    Eventually there may be a way of asking the compiler to choose a
  162. register automatically, but first we need to figure out how it should
  163. choose and how to enable you to guide the choice.  No solution is
  164. evident.
  165.    Defining such a register variable does not reserve the register; it
  166. remains available for other uses in places where flow control determines
  167. the variable's value is not live.  However, these registers are made
  168. unavailable for use in the reload pass.  I would not be surprised if
  169. excessive use of this feature leaves the compiler too few available
  170. registers to compile certain functions.
  171. File: gcc.info,  Node: Alternate Keywords,  Next: Incomplete Enums,  Prev: Explicit Reg Vars,  Up: C Extensions
  172. Alternate Keywords
  173. ==================
  174.    The option `-traditional' disables certain keywords; `-ansi'
  175. disables certain others.  This causes trouble when you want to use GNU C
  176. extensions, or ANSI C features, in a general-purpose header file that
  177. should be usable by all programs, including ANSI C programs and
  178. traditional ones.  The keywords `asm', `typeof' and `inline' cannot be
  179. used since they won't work in a program compiled with `-ansi', while
  180. the keywords `const', `volatile', `signed', `typeof' and `inline' won't
  181. work in a program compiled with `-traditional'.
  182.    The way to solve these problems is to put `__' at the beginning and
  183. end of each problematical keyword.  For example, use `__asm__' instead
  184. of `asm', `__const__' instead of `const', and `__inline__' instead of
  185. `inline'.
  186.    Other C compilers won't accept these alternative keywords; if you
  187. want to compile with another compiler, you can define the alternate
  188. keywords as macros to replace them with the customary keywords.  It
  189. looks like this:
  190.      #ifndef __GNUC__
  191.      #define __asm__ asm
  192.      #endif
  193.    `-pedantic' causes warnings for many GNU C extensions.  You can
  194. prevent such warnings within one expression by writing `__extension__'
  195. before the expression.  `__extension__' has no effect aside from this.
  196. File: gcc.info,  Node: Incomplete Enums,  Next: Function Names,  Prev: Alternate Keywords,  Up: C Extensions
  197. Incomplete `enum' Types
  198. =======================
  199.    You can define an `enum' tag without specifying its possible values.
  200. This results in an incomplete type, much like what you get if you write
  201. `struct foo' without describing the elements.  A later declaration
  202. which does specify the possible values completes the type.
  203.    You can't allocate variables or storage using the type while it is
  204. incomplete.  However, you can work with pointers to that type.
  205.    This extension may not be very useful, but it makes the handling of
  206. `enum' more consistent with the way `struct' and `union' are handled.
  207.    This extension is not supported by GNU C++.
  208. File: gcc.info,  Node: Function Names,  Prev: Incomplete Enums,  Up: C Extensions
  209. Function Names as Strings
  210. =========================
  211.    GNU CC predefines two string variables to be the name of the current
  212. function.  The variable `__FUNCTION__' is the name of the function as
  213. it appears in the source.  The variable `__PRETTY_FUNCTION__' is the
  214. name of the function pretty printed in a language specific fashion.
  215.    These names are always the same in a C function, but in a C++
  216. function they may be different.  For example, this program:
  217.      extern "C" {
  218.      extern int printf (char *, ...);
  219.      }
  220.      
  221.      class a {
  222.       public:
  223.        sub (int i)
  224.          {
  225.            printf ("__FUNCTION__ = %s\n", __FUNCTION__);
  226.            printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
  227.          }
  228.      };
  229.      
  230.      int
  231.      main (void)
  232.      {
  233.        a ax;
  234.        ax.sub (0);
  235.        return 0;
  236.      }
  237. gives this output:
  238.      __FUNCTION__ = sub
  239.      __PRETTY_FUNCTION__ = int  a::sub (int)
  240.    These names are not macros: they are predefined string variables.
  241. For example, `#ifdef __FUNCTION__' does not have any special meaning
  242. inside a function, since the preprocessor does not do anything special
  243. with the identifier `__FUNCTION__'.
  244. File: gcc.info,  Node: C++ Extensions,  Next: Trouble,  Prev: C Extensions,  Up: Top
  245. Extensions to the C++ Language
  246. ******************************
  247.    The GNU compiler provides these extensions to the C++ language (and
  248. you can also use most of the C language extensions in your C++
  249. programs).  If you want to write code that checks whether these
  250. features are available, you can test for the GNU compiler the same way
  251. as for C programs: check for a predefined macro `__GNUC__'.  You can
  252. also use `__GNUG__' to test specifically for GNU C++ (*note Standard
  253. Predefined Macros: (cpp.info)Standard Predefined.).
  254. * Menu:
  255. * Naming Results::      Giving a name to C++ function return values.
  256. * Min and Max::        C++ Minimum and maximum operators.
  257. * Destructors and Goto:: Goto is safe to use in C++ even when destructors
  258.                            are needed.
  259. * C++ Interface::       You can use a single C++ header file for both
  260.                          declarations and definitions.
  261. * Template Instantiation:: Methods for ensuring that exactly one copy of
  262.                          each needed template instantiation is emitted.
  263. * C++ Signatures::    You can specify abstract types to get subtype
  264.              polymorphism independent from inheritance.
  265. File: gcc.info,  Node: Naming Results,  Next: Min and Max,  Up: C++ Extensions
  266. Named Return Values in C++
  267. ==========================
  268.    GNU C++ extends the function-definition syntax to allow you to
  269. specify a name for the result of a function outside the body of the
  270. definition, in C++ programs:
  271.      TYPE
  272.      FUNCTIONNAME (ARGS) return RESULTNAME;
  273.      {
  274.        ...
  275.        BODY
  276.        ...
  277.      }
  278.    You can use this feature to avoid an extra constructor call when a
  279. function result has a class type.  For example, consider a function
  280. `m', declared as `X v = m ();', whose result is of class `X':
  281.      X
  282.      m ()
  283.      {
  284.        X b;
  285.        b.a = 23;
  286.        return b;
  287.      }
  288.    Although `m' appears to have no arguments, in fact it has one
  289. implicit argument: the address of the return value.  At invocation, the
  290. address of enough space to hold `v' is sent in as the implicit argument.
  291. Then `b' is constructed and its `a' field is set to the value 23.
  292. Finally, a copy constructor (a constructor of the form `X(X&)') is
  293. applied to `b', with the (implicit) return value location as the
  294. target, so that `v' is now bound to the return value.
  295.    But this is wasteful.  The local `b' is declared just to hold
  296. something that will be copied right out.  While a compiler that
  297. combined an "elision" algorithm with interprocedural data flow analysis
  298. could conceivably eliminate all of this, it is much more practical to
  299. allow you to assist the compiler in generating efficient code by
  300. manipulating the return value explicitly, thus avoiding the local
  301. variable and copy constructor altogether.
  302.    Using the extended GNU C++ function-definition syntax, you can avoid
  303. the temporary allocation and copying by naming `r' as your return value
  304. at the outset, and assigning to its `a' field directly:
  305.      X
  306.      m () return r;
  307.      {
  308.        r.a = 23;
  309.      }
  310. The declaration of `r' is a standard, proper declaration, whose effects
  311. are executed *before* any of the body of `m'.
  312.    Functions of this type impose no additional restrictions; in
  313. particular, you can execute `return' statements, or return implicitly by
  314. reaching the end of the function body ("falling off the edge").  Cases
  315.      X
  316.      m () return r (23);
  317.      {
  318.        return;
  319.      }
  320. (or even `X m () return r (23); { }') are unambiguous, since the return
  321. value `r' has been initialized in either case.  The following code may
  322. be hard to read, but also works predictably:
  323.      X
  324.      m () return r;
  325.      {
  326.        X b;
  327.        return b;
  328.      }
  329.    The return value slot denoted by `r' is initialized at the outset,
  330. but the statement `return b;' overrides this value.  The compiler deals
  331. with this by destroying `r' (calling the destructor if there is one, or
  332. doing nothing if there is not), and then reinitializing `r' with `b'.
  333.    This extension is provided primarily to help people who use
  334. overloaded operators, where there is a great need to control not just
  335. the arguments, but the return values of functions.  For classes where
  336. the copy constructor incurs a heavy performance penalty (especially in
  337. the common case where there is a quick default constructor), this is a
  338. major savings.  The disadvantage of this extension is that you do not
  339. control when the default constructor for the return value is called: it
  340. is always called at the beginning.
  341. File: gcc.info,  Node: Min and Max,  Next: Destructors and Goto,  Prev: Naming Results,  Up: C++ Extensions
  342. Minimum and Maximum Operators in C++
  343. ====================================
  344.    It is very convenient to have operators which return the "minimum"
  345. or the "maximum" of two arguments.  In GNU C++ (but not in GNU C),
  346. `A <? B'
  347.      is the "minimum", returning the smaller of the numeric values A
  348.      and B;
  349. `A >? B'
  350.      is the "maximum", returning the larger of the numeric values A and
  351.      B.
  352.    These operations are not primitive in ordinary C++, since you can
  353. use a macro to return the minimum of two things in C++, as in the
  354. following example.
  355.      #define MIN(X,Y) ((X) < (Y) ? : (X) : (Y))
  356. You might then use `int min = MIN (i, j);' to set MIN to the minimum
  357. value of variables I and J.
  358.    However, side effects in `X' or `Y' may cause unintended behavior.
  359. For example, `MIN (i++, j++)' will fail, incrementing the smaller
  360. counter twice.  A GNU C extension allows you to write safe macros that
  361. avoid this kind of problem (*note Naming an Expression's Type: Naming
  362. Types.).  However, writing `MIN' and `MAX' as macros also forces you to
  363. use function-call notation notation for a fundamental arithmetic
  364. operation.  Using GNU C++ extensions, you can write `int min = i <? j;'
  365. instead.
  366.    Since `<?' and `>?' are built into the compiler, they properly
  367. handle expressions with side-effects;  `int min = i++ <? j++;' works
  368. correctly.
  369. File: gcc.info,  Node: Destructors and Goto,  Next: C++ Interface,  Prev: Min and Max,  Up: C++ Extensions
  370. `goto' and Destructors in GNU C++
  371. =================================
  372.    In C++ programs, you can safely use the `goto' statement.  When you
  373. use it to exit a block which contains aggregates requiring destructors,
  374. the destructors will run before the `goto' transfers control.  (In ANSI
  375. C++, `goto' is restricted to targets within the current block.)
  376.    The compiler still forbids using `goto' to *enter* a scope that
  377. requires constructors.
  378. File: gcc.info,  Node: C++ Interface,  Next: Template Instantiation,  Prev: Destructors and Goto,  Up: C++ Extensions
  379. Declarations and Definitions in One Header
  380. ==========================================
  381.    C++ object definitions can be quite complex.  In principle, your
  382. source code will need two kinds of things for each object that you use
  383. across more than one source file.  First, you need an "interface"
  384. specification, describing its structure with type declarations and
  385. function prototypes.  Second, you need the "implementation" itself.  It
  386. can be tedious to maintain a separate interface description in a header
  387. file, in parallel to the actual implementation.  It is also dangerous,
  388. since separate interface and implementation definitions may not remain
  389. parallel.
  390.    With GNU C++, you can use a single header file for both purposes.
  391.      *Warning:* The mechanism to specify this is in transition.  For the
  392.      nonce, you must use one of two `#pragma' commands; in a future
  393.      release of GNU C++, an alternative mechanism will make these
  394.      `#pragma' commands unnecessary.
  395.    The header file contains the full definitions, but is marked with
  396. `#pragma interface' in the source code.  This allows the compiler to
  397. use the header file only as an interface specification when ordinary
  398. source files incorporate it with `#include'.  In the single source file
  399. where the full implementation belongs, you can use either a naming
  400. convention or `#pragma implementation' to indicate this alternate use
  401. of the header file.
  402. `#pragma interface'
  403. `#pragma interface "SUBDIR/OBJECTS.h"'
  404.      Use this directive in *header files* that define object classes,
  405.      to save space in most of the object files that use those classes.
  406.      Normally, local copies of certain information (backup copies of
  407.      inline member functions, debugging information, and the internal
  408.      tables that implement virtual functions) must be kept in each
  409.      object file that includes class definitions.  You can use this
  410.      pragma to avoid such duplication.  When a header file containing
  411.      `#pragma interface' is included in a compilation, this auxiliary
  412.      information will not be generated (unless the main input source
  413.      file itself uses `#pragma implementation').  Instead, the object
  414.      files will contain references to be resolved at link time.
  415.      The second form of this directive is useful for the case where you
  416.      have multiple headers with the same name in different directories.
  417.      If you use this form, you must specify the same string to `#pragma
  418.      implementation'.
  419. `#pragma implementation'
  420. `#pragma implementation "OBJECTS.h"'
  421.      Use this pragma in a *main input file*, when you want full output
  422.      from included header files to be generated (and made globally
  423.      visible).  The included header file, in turn, should use `#pragma
  424.      interface'.  Backup copies of inline member functions, debugging
  425.      information, and the internal tables used to implement virtual
  426.      functions are all generated in implementation files.
  427.      If you use `#pragma implementation' with no argument, it applies to
  428.      an include file with the same basename(1) as your source file.
  429.      For example, in `allclass.cc', `#pragma implementation' by itself
  430.      is equivalent to `#pragma implementation "allclass.h"'.
  431.      In versions of GNU C++ prior to 2.6.0 `allclass.h' was treated as
  432.      an implementation file whenever you would include it from
  433.      `allclass.cc' even if you never specified `#pragma
  434.      implementation'.  This was deemed to be more trouble than it was
  435.      worth, however, and disabled.
  436.      If you use an explicit `#pragma implementation', it must appear in
  437.      your source file *before* you include the affected header files.
  438.      Use the string argument if you want a single implementation file to
  439.      include code from multiple header files.  (You must also use
  440.      `#include' to include the header file; `#pragma implementation'
  441.      only specifies how to use the file--it doesn't actually include
  442.      it.)
  443.      There is no way to split up the contents of a single header file
  444.      into multiple implementation files.
  445.    `#pragma implementation' and `#pragma interface' also have an effect
  446. on function inlining.
  447.    If you define a class in a header file marked with `#pragma
  448. interface', the effect on a function defined in that class is similar to
  449. an explicit `extern' declaration--the compiler emits no code at all to
  450. define an independent version of the function.  Its definition is used
  451. only for inlining with its callers.
  452.    Conversely, when you include the same header file in a main source
  453. file that declares it as `#pragma implementation', the compiler emits
  454. code for the function itself; this defines a version of the function
  455. that can be found via pointers (or by callers compiled without
  456. inlining).  If all calls to the function can be inlined, you can avoid
  457. emitting the function by compiling with `-fno-implement-inlines'.  If
  458. any calls were not inlined, you will get linker errors.
  459.    ---------- Footnotes ----------
  460.    (1)  A file's "basename" was the name stripped of all leading path
  461. information and of trailing suffixes, such as `.h' or `.C' or `.cc'.
  462. File: gcc.info,  Node: Template Instantiation,  Next: C++ Signatures,  Prev: C++ Interface,  Up: C++ Extensions
  463. Where's the Template?
  464. =====================
  465.    C++ templates are the first language feature to require more
  466. intelligence from the environment than one usually finds on a UNIX
  467. system.  Somehow the compiler and linker have to make sure that each
  468. template instance occurs exactly once in the executable if it is needed,
  469. and not at all otherwise.  There are two basic approaches to this
  470. problem, which I will refer to as the Borland model and the Cfront
  471. model.
  472. Borland model
  473.      Borland C++ solved the template instantiation problem by adding
  474.      the code equivalent of common blocks to their linker; template
  475.      instances are emitted in each translation unit that uses them, and
  476.      they are collapsed together at run time.  The advantage of this
  477.      model is that the linker only has to consider the object files
  478.      themselves; there is no external complexity to worry about.  This
  479.      disadvantage is that compilation time is increased because the
  480.      template code is being compiled repeatedly.  Code written for this
  481.      model tends to include definitions of all member templates in the
  482.      header file, since they must be seen to be compiled.
  483. Cfront model
  484.      The AT&T C++ translator, Cfront, solved the template instantiation
  485.      problem by creating the notion of a template repository, an
  486.      automatically maintained place where template instances are
  487.      stored.  As individual object files are built, notes are placed in
  488.      the repository to record where templates and potential type
  489.      arguments were seen so that the subsequent instantiation step
  490.      knows where to find them.  At link time, any needed instances are
  491.      generated and linked in.  The advantages of this model are more
  492.      optimal compilation speed and the ability to use the system
  493.      linker; to implement the Borland model a compiler vendor also
  494.      needs to replace the linker.  The disadvantages are vastly
  495.      increased complexity, and thus potential for error; theoretically,
  496.      this should be just as transparent, but in practice it has been
  497.      very difficult to build multiple programs in one directory and one
  498.      program in multiple directories using Cfront.  Code written for
  499.      this model tends to separate definitions of non-inline member
  500.      templates into a separate file, which is magically found by the
  501.      link preprocessor when a template needs to be instantiated.
  502.    Currently, g++ implements neither automatic model.  In the mean time,
  503. you have three options for dealing with template instantiations:
  504.   1. Do nothing.  Pretend g++ does implement automatic instantiation
  505.      management.  Code written for the Borland model will work fine, but
  506.      each translation unit will contain instances of each of the
  507.      templates it uses.  In a large program, this can lead to an
  508.      unacceptable amount of code duplication.
  509.   2. Add `#pragma interface' to all files containing template
  510.      definitions.  For each of these files, add `#pragma implementation
  511.      "FILENAME"' to the top of some `.C' file which `#include's it.
  512.      Then compile everything with -fexternal-templates.  The templates
  513.      will then only be expanded in the translation unit which
  514.      implements them (i.e. has a `#pragma implementation' line for the
  515.      file where they live); all other files will use external
  516.      references.  If you're lucky, everything should work properly.  If
  517.      you get undefined symbol errors, you need to make sure that each
  518.      template instance which is used in the program is used in the file
  519.      which implements that template.  If you don't have any use for a
  520.      particular instance in that file, you can just instantiate it
  521.      explicitly, using the syntax from the latest C++ working paper:
  522.           template class A<int>;
  523.           template ostream& operator << (ostream&, const A<int>&);
  524.      This strategy will work with code written for either model.  If
  525.      you are using code written for the Cfront model, the file
  526.      containing a class template and the file containing its member
  527.      templates should be implemented in the same translation unit.
  528.      A slight variation on this approach is to use the flag
  529.      -falt-external-templates instead; this flag causes template
  530.      instances to be emitted in the translation unit that implements
  531.      the header where they are first instantiated, rather than the one
  532.      which implements the file where the templates are defined.  This
  533.      header must be the same in all translation units, or things are
  534.      likely to break.
  535.      *Note Declarations and Definitions in One Header: C++ Interface,
  536.      for more discussion of these pragmas.
  537.   3. Explicitly instantiate all the template instances you use, and
  538.      compile with -fno-implicit-templates.  This is probably your best
  539.      bet; it may require more knowledge of exactly which templates you
  540.      are using, but it's less mysterious than the previous approach,
  541.      and it doesn't require any `#pragma's or other g++-specific code.
  542.      You can scatter the instantiations throughout your program, you
  543.      can create one big file to do all the instantiations, or you can
  544.      create tiny files like
  545.           #include "Foo.h"
  546.           #include "Foo.cc"
  547.           
  548.           template class Foo<int>;
  549.      for each instance you need, and create a template instantiation
  550.      library from those.  I'm partial to the last, but your mileage may
  551.      vary.  If you are using Cfront-model code, you can probably get
  552.      away with not using -fno-implicit-templates when compiling files
  553.      that don't `#include' the member template definitions.
  554. File: gcc.info,  Node: C++ Signatures,  Prev: Template Instantiation,  Up: C++ Extensions
  555. Type Abstraction using Signatures
  556. =================================
  557.    In GNU C++, you can use the keyword `signature' to define a
  558. completely abstract class interface as a datatype.  You can connect this
  559. abstraction with actual classes using signature pointers.  If you want
  560. to use signatures, run the GNU compiler with the `-fhandle-signatures'
  561. command-line option.  (With this option, the compiler reserves a second
  562. keyword `sigof' as well, for a future extension.)
  563.    Roughly, signatures are type abstractions or interfaces of classes.
  564. Some other languages have similar facilities.  C++ signatures are
  565. related to ML's signatures, Haskell's type classes, definition modules
  566. in Modula-2, interface modules in Modula-3, abstract types in Emerald,
  567. type modules in Trellis/Owl, categories in Scratchpad II, and types in
  568. POOL-I.  For a more detailed discussion of signatures, see `Signatures:
  569. A Language Extension for Improving Type Abstraction and Subtype
  570. Polymorphism in C++' by Gerald Baumgartner and Vincent F. Russo (Tech
  571. report CSD-TR-95-051, Dept. of Computer Sciences, Purdue University,
  572. August 1995, a slightly improved version appeared in
  573. *Software--Practice & Experience*, 25(8), pp. 863-889, August 1995).
  574. You can get the tech report by anonymous FTP from `ftp.cs.purdue.edu'
  575. in `pub/gb/Signature-design.ps.gz'.
  576.    Syntactically, a signature declaration is a collection of member
  577. function declarations and nested type declarations.  For example, this
  578. signature declaration defines a new abstract type `S' with member
  579. functions `int foo ()' and `int bar (int)':
  580.      signature S
  581.      {
  582.        int foo ();
  583.        int bar (int);
  584.      };
  585.    Since signature types do not include implementation definitions, you
  586. cannot write an instance of a signature directly.  Instead, you can
  587. define a pointer to any class that contains the required interfaces as a
  588. "signature pointer".  Such a class "implements" the signature type.
  589.    To use a class as an implementation of `S', you must ensure that the
  590. class has public member functions `int foo ()' and `int bar (int)'.
  591. The class can have other member functions as well, public or not; as
  592. long as it offers what's declared in the signature, it is suitable as
  593. an implementation of that signature type.
  594.    For example, suppose that `C' is a class that meets the requirements
  595. of signature `S' (`C' "conforms to" `S').  Then
  596.      C obj;
  597.      S * p = &obj;
  598. defines a signature pointer `p' and initializes it to point to an
  599. object of type `C'.  The member function call `int i = p->foo ();'
  600. executes `obj.foo ()'.
  601.    Abstract virtual classes provide somewhat similar facilities in
  602. standard C++.  There are two main advantages to using signatures
  603. instead:
  604.   1. Subtyping becomes independent from inheritance.  A class or
  605.      signature type `T' is a subtype of a signature type `S'
  606.      independent of any inheritance hierarchy as long as all the member
  607.      functions declared in `S' are also found in `T'.  So you can
  608.      define a subtype hierarchy that is completely independent from any
  609.      inheritance (implementation) hierarchy, instead of being forced to
  610.      use types that mirror the class inheritance hierarchy.
  611.   2. Signatures allow you to work with existing class hierarchies as
  612.      implementations of a signature type.  If those class hierarchies
  613.      are only available in compiled form, you're out of luck with
  614.      abstract virtual classes, since an abstract virtual class cannot
  615.      be retrofitted on top of existing class hierarchies.  So you would
  616.      be required to write interface classes as subtypes of the abstract
  617.      virtual class.
  618.    There is one more detail about signatures.  A signature declaration
  619. can contain member function *definitions* as well as member function
  620. declarations.  A signature member function with a full definition is
  621. called a *default implementation*; classes need not contain that
  622. particular interface in order to conform.  For example, a class `C' can
  623. conform to the signature
  624.      signature T
  625.      {
  626.        int f (int);
  627.        int f0 () { return f (0); };
  628.      };
  629. whether or not `C' implements the member function `int f0 ()'.  If you
  630. define `C::f0', that definition takes precedence; otherwise, the
  631. default implementation `S::f0' applies.
  632. File: gcc.info,  Node: Trouble,  Next: Bugs,  Prev: C++ Extensions,  Up: Top
  633. Known Causes of Trouble with GNU CC
  634. ***********************************
  635.    This section describes known problems that affect users of GNU CC.
  636. Most of these are not GNU CC bugs per se--if they were, we would fix
  637. them.  But the result for a user may be like the result of a bug.
  638.    Some of these problems are due to bugs in other software, some are
  639. missing features that are too much work to add, and some are places
  640. where people's opinions differ as to what is best.
  641. * Menu:
  642. * Actual Bugs::              Bugs we will fix later.
  643. * Installation Problems::     Problems that manifest when you install GNU CC.
  644. * Cross-Compiler Problems::   Common problems of cross compiling with GNU CC.
  645. * Interoperation::      Problems using GNU CC with other compilers,
  646.                and with certain linkers, assemblers and debuggers.
  647. * External Bugs::    Problems compiling certain programs.
  648. * Incompatibilities::   GNU CC is incompatible with traditional C.
  649. * Fixed Headers::       GNU C uses corrected versions of system header files.
  650.                            This is necessary, but doesn't always work smoothly.
  651. * Standard Libraries::  GNU C uses the system C library, which might not be
  652.                            compliant with the ISO/ANSI C standard.
  653. * Disappointments::     Regrettable things we can't change, but not quite bugs.
  654. * C++ Misunderstandings::     Common misunderstandings with GNU C++.
  655. * Protoize Caveats::    Things to watch out for when using `protoize'.
  656. * Non-bugs::        Things we think are right, but some others disagree.
  657. * Warnings and Errors:: Which problems in your code get warnings,
  658.                          and which get errors.
  659. File: gcc.info,  Node: Actual Bugs,  Next: Installation Problems,  Up: Trouble
  660. Actual Bugs We Haven't Fixed Yet
  661. ================================
  662.    * The `fixincludes' script interacts badly with automounters; if the
  663.      directory of system header files is automounted, it tends to be
  664.      unmounted while `fixincludes' is running.  This would seem to be a
  665.      bug in the automounter.  We don't know any good way to work around
  666.      it.
  667.    * The `fixproto' script will sometimes add prototypes for the
  668.      `sigsetjmp' and `siglongjmp' functions that reference the
  669.      `jmp_buf' type before that type is defined.  To work around this,
  670.      edit the offending file and place the typedef in front of the
  671.      prototypes.
  672.    * There are several obscure case of mis-using struct, union, and
  673.      enum tags that are not detected as errors by the compiler.
  674.    * When `-pedantic-errors' is specified, GNU C will incorrectly give
  675.      an error message when a function name is specified in an expression
  676.      involving the comma operator.
  677.    * Loop unrolling doesn't work properly for certain C++ programs.
  678.      This is a bug in the C++ front end.  It sometimes emits incorrect
  679.      debug info, and the loop unrolling code is unable to recover from
  680.      this error.
  681.