This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: #pragma interface and #pragma implementation
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Wednesday 02 June 2004 05:06, Giovanni Bajo wrote:
> Steven T. Hatton wrote:
> > 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.
>
> Of course. To keep a function in a header file, you must ensure your
> function has internal linkage by making it inline or static (or within an
> anonymous namespace, etc.). If it is a member function, you can make it
> inline explicitly, or implicitly (by defining it within the class
> definition).
>
> Giovanni Bajo
Yes, this explains the remedy, but not the affliction. I'm confident it has
something to do with the structure of the resulting translation unit created
by preprocessing C++. I haven't found time to experiment with any tools for
viewing translation units in order to determine how they are actually
structured. Ostensibly, a header and a source file are the same type of
entity. The only difference being the conventions of how they are used.
That makes it a bit hard to understand how one ends up with multiple
definitions of a function when it is defined within an include guard.
My understand is that once the macro _UGLY_VARIANT_OF_FILENAME_H was defined,
the contents of the #ifndef ... #endif would be ignored by the preprocessor.
That makes it difficult for me to understand how the function is getting
defined twice.
- --
Regards,
Steven
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)
iD8DBQFAvhfawX61+IL0QsMRAoUWAKDA0R8jNg2tRTYUT2TgAQgqdrtNsgCg3eSX
kOTWtdbMyzFTU5BhOhiaOZM=
=bvSe
-----END PGP SIGNATURE-----