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 Wednesday 02 June 2004 03:11, Per Bothner wrote:
> Steven T. Hatton wrote:
> > Your comments seem somewhat inconsistent with what the documentation
> > says.
> >
> > "Declarations and Definitions in One Header
...
> > With GNU C++, you can use a single header file for both purposes."
>
> Wow, I had no idea the documentation made this claim.
>
> I think I can safely say that this documentation is a wee bit misleading
> ...  It seems to have been written by someone who didn't quite
> understand the #pragma.  Either that, or their meaning changed.  Or
> perhaps just my understanding of it changed ...
>
> #pragma interface just effects the one header file it appears in.
> It causes supression of vtables, debug info, and inline functions
> for declarations (primarily classes) in that header file *unless*
> there is a corresponding #pragma implementation.  In the implementing
> .o file, the vtables etc are made global, so they can be shared by
> other .o files.  The intent is that each foo.h is an interface that
> is implemented by one foo.c file.

I'll have to revisit that after some sleep.
...

> I'd say it's an incorrect understanding - but understandable based on
> the manual.  However, I'm confused by why you'd "previously been 
> necessary to put the implementation in the source file to prevent
> multiple definition error".  That suggests to me some further confusion
> on your part as to how C++ works.

I don't claim to understand why it happens, but I have encountered many 
circumstances in which moving an implementation of a function out of a header 
and into a source file eliminated errors saying thing had been defined 
multiple times.  I don't have a concrete example available.  It often seems 
to have corresponded to #including the header in a source file.  It didn't 
seem to matter that I had used include guards.  This last part is especially 
confusing.

- -- 
Regards,
Steven
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQFAvYrUwX61+IL0QsMRAoGPAJwMvhOO0dBAmw3AKYGUUhByVzR50gCgm+zp
611LHQ3ELaHpIX2CizQHEv8=
=JYkB
-----END PGP SIGNATURE-----


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