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


Steven T. Hatton wrote:


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."

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.

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?

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. -- --Per Bothner per@bothner.com http://per.bothner.com/


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