This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Anonymous Namespaces
- From: Kevin Atkinson <kevina at gnu dot org>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 31 Jan 2004 04:40:06 -0500 (EST)
- Subject: Anonymous Namespaces
Is there a reason gcc 3.4 does not treat functions inside an anonymous
namespace as having static linkage. In particular 'gcc -O3' inlines "f"
but still emits code for it in the following simple example:
#include <iostream>
namespace {
void f()
{
std::cout << "Hello\n";
}
}
int main()
{
f();
f();
}
If I include static in front of "void f()" gcc does not emit code for "f".
I see this as a serious limitations for C++ programs as it means that the
new unit-at-a-time optimizations will be of limited usefulness since
member functions can not be declared to have static linkage.
It would seam to me that all functions (and variables for that matter)
inside an anonymous namespace should have static linkage since they can
only be used inside the current file.
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.
Thanks in advance.
Version info:
/opt/gcc/bin/gcc -v
Reading specs from /opt/gcc/bin/../lib/gcc/i686-pc-linux-gnu/3.4.0/specs
Configured with: ../src/configure --prefix=/opt/gcc/
--enable-languages=c,c++ --with-arch=i686
Thread model: posix
gcc version 3.4.0 20040128 (prerelease)
---
http://kevin.atkinson.dhs.org