This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: #pragma interface and #pragma implementation


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Tuesday 01 June 2004 20:10, Joe Buck wrote:
> On Tue, Jun 01, 2004 at 03:42:42PM -0400, Steven T. Hatton wrote:
> > I've been experimenting with the #pragma directives ...
>
> I would advise against the use of #pragma interface and #pragma
> implementation.  They are perhaps not quite obsolete, but they are
> little-used today.
>
> The original purpose of these directives was to permit the compiler to
> generate only one global copy of certain types of objects, like virtual
> function tables and non-inline copies of inline functions.  However, this
> hack is far less necessary now, for two reasons:
>
> 1) For years now, g++ has implemented the "cfront hack": the virtual
> function table is emitted only in the object file that implements the
> first non-inline virtual function of the class.
>
> 2) On many platforms (including GNU/Linux and the BSDs) the linker is
> capable of removing all but one copy of functions that are emitted at
> multiple points.

Your comments seem somewhat inconsistent with what the documentation says.  

"Declarations and Definitions in One Header

C++ object definitions can be quite complex. In principle, your source code 
will need two kinds of things for each object that you use across more than 
one source file. First, you need an interface specification, describing its 
structure with type declarations and function prototypes. Second, you need 
the implementation itself. It can be tedious to maintain a separate interface 
description in a header file, in parallel to the actual implementation. It is 
also dangerous, since separate interface and implementation definitions may 
not remain parallel.

With GNU C++, you can use a single header file for both purposes."

Or perhaps I'm failing to understand the relationship.  I may have 
misunderstood what the effect of the #pragmas actually is.  I was expecting 
to be able to move code from source files (.cc) to header files (.h) in 
situations where it had previously been necessary to put the implementation 
in the source file to prevent multiple definition error.

Is this an incorrect understanding? 
- -- 
Regards,
Steven
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAvWgUwX61+IL0QsMRAtGKAJ9K4IEf1wCnfZjAiCs4sF+MHZUzaACgplPZ
oF7PpDIeiOxKnpr6gAggWLQ=
=lcvw
-----END PGP SIGNATURE-----


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]