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]

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


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