This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Anonymous Namespaces
- From: Kevin Atkinson <kevina at gnu dot org>
- To: Andrew Pinski <pinskia at physics dot uc dot edu>
- Cc: gcc at gcc dot gnu dot org
- Date: Sat, 31 Jan 2004 05:07:52 -0500 (EST)
- Subject: Re: Anonymous Namespaces
On Sat, 31 Jan 2004, Andrew Pinski wrote:
>
> On Jan 31, 2004, at 01:40, Kevin Atkinson wrote:
> > So, is there a reason there not? If so, is there a way to declare
> > member
> > functions as having static linkage so that the unit-at-a-time code can
> > optimize them.
>
> Yes because that is not the way C++ works, anonymous namespaces only
> give an unique name for that translation unit and that is it; it does
> not change the linkage of the symbol at all.
Is there any harm is doing so? There is no way for the symbol defined in
an anonymous namespace to be used outside if the translation unit. It
should have the same effect as static. The new unit-at-a-time optimizations
will be a lot more beneficial in C++ programs is anonymous namespaces were
treated that way.
Of course like C if an address of static function is taken then the
compiler must treat it as if it was external (ie, it has to emit code for
it and it can't use special calling conventions).
By member functions I mean the case in which the entire class is defined
inside an anonymous namespace ie:
namespace {
class F {
public:
void f();
};
void F::f() {...}
}
There is no way any part of F can be accessed out side of the translation
unit unless an address is taken, which included the case if a function is
virtual.
OR am I completely misunderstanding the point of anonymous namespaces?
--
http://kevin.atkinson.dhs.org