gcc: C++ Interface

1 
1 7.4 C++ Interface and Implementation Pragmas
1 ============================================
1 
1 '#pragma interface' and '#pragma implementation' provide the user with a
1 way of explicitly directing the compiler to emit entities with vague
1 linkage (and debugging information) in a particular translation unit.
1 
1  _Note:_ These '#pragma's have been superceded as of GCC 2.7.2 by COMDAT
11 support and the "key method" heuristic mentioned in ⇒Vague
 Linkage.  Using them can actually cause your program to grow due to
1 unnecessary out-of-line copies of inline functions.
1 
1 '#pragma interface'
1 '#pragma interface "SUBDIR/OBJECTS.h"'
1      Use this directive in _header files_ that define object classes, to
1      save space in most of the object files that use those classes.
1      Normally, local copies of certain information (backup copies of
1      inline member functions, debugging information, and the internal
1      tables that implement virtual functions) must be kept in each
1      object file that includes class definitions.  You can use this
1      pragma to avoid such duplication.  When a header file containing
1      '#pragma interface' is included in a compilation, this auxiliary
1      information is not generated (unless the main input source file
1      itself uses '#pragma implementation').  Instead, the object files
1      contain references to be resolved at link time.
1 
1      The second form of this directive is useful for the case where you
1      have multiple headers with the same name in different directories.
1      If you use this form, you must specify the same string to '#pragma
1      implementation'.
1 
1 '#pragma implementation'
1 '#pragma implementation "OBJECTS.h"'
1      Use this pragma in a _main input file_, when you want full output
1      from included header files to be generated (and made globally
1      visible).  The included header file, in turn, should use '#pragma
1      interface'.  Backup copies of inline member functions, debugging
1      information, and the internal tables used to implement virtual
1      functions are all generated in implementation files.
1 
1      If you use '#pragma implementation' with no argument, it applies to
1      an include file with the same basename(1) as your source file.  For
1      example, in 'allclass.cc', giving just '#pragma implementation' by
1      itself is equivalent to '#pragma implementation "allclass.h"'.
1 
1      Use the string argument if you want a single implementation file to
1      include code from multiple header files.  (You must also use
1      '#include' to include the header file; '#pragma implementation'
1      only specifies how to use the file--it doesn't actually include
1      it.)
1 
1      There is no way to split up the contents of a single header file
1      into multiple implementation files.
1 
1  '#pragma implementation' and '#pragma interface' also have an effect on
1 function inlining.
1 
1  If you define a class in a header file marked with '#pragma interface',
1 the effect on an inline function defined in that class is similar to an
1 explicit 'extern' declaration--the compiler emits no code at all to
1 define an independent version of the function.  Its definition is used
1 only for inlining with its callers.
1 
1  Conversely, when you include the same header file in a main source file
1 that declares it as '#pragma implementation', the compiler emits code
1 for the function itself; this defines a version of the function that can
1 be found via pointers (or by callers compiled without inlining).  If all
1 calls to the function can be inlined, you can avoid emitting the
1 function by compiling with '-fno-implement-inlines'.  If any calls are
1 not inlined, you will get linker errors.
1 
1    ---------- Footnotes ----------
1 
1    (1) A file's "basename" is the name stripped of all leading path
1 information and of trailing suffixes, such as '.h' or '.C' or '.cc'.
1