provide the user with a way of explicitly directing the compiler to emit entities with vague linkage (and debugging information) in a particular translation unit.
s have been superceded as of GCC 2.7.2 by COMDAT support and the “key method” heuristic mentioned in Vague Linkage
. Using them can actually cause your program to grow due to unnecessary out-of-line copies of inline functions.
#pragma interface "subdir
The second form of this directive is useful for the case where you have multiple headers with the same name in different directories. If you use this form, you must specify the same string to ‘
#pragma implementation "objects
If you use ‘ #pragma implementation ’ with no argument, it applies to an include file with the same basename 1 as your source file. For example, in allclass.cc , giving just ‘ #pragma implementation ’ by itself is equivalent to ‘ #pragma implementation "allclass.h" ’.
Use the string argument if you want a single implementation file to include code from multiple header files. (You must also use ‘ #include ’ to include the header file; ‘ #pragma implementation ’ only specifies how to use the file—it doesn't actually include it.)
There is no way to split up the contents of a single header file into multiple implementation files.
If you define a class in a header file marked with ‘
’, the effect on an inline function defined in that class is similar to an explicit
declaration—the compiler emits no code at all to define an independent version of the function. Its definition is used only for inlining with its callers.
Conversely, when you include the same header file in a main source file that declares it as ‘ #pragma implementation ’, the compiler emits code for the function itself; this defines a version of the function that can be found via pointers (or by callers compiled without inlining). If all calls to the function can be inlined, you can avoid emitting the function by compiling with -fno-implement-inlines . If any calls are not inlined, you will get linker errors.
[1 ] A file's basename is the name stripped of all leading path information and of trailing suffixes, such as ‘ .h ’ or ‘ .C ’ or ‘ .cc ’.