[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Anonymous namespace implications - footprints
From: |
kobi . cohenarazi |
Subject: |
Anonymous namespace implications - footprints |
Date: |
18 Jun 2006 14:13:51 -0700 |
User-agent: |
G2/0.2 |
Hi,
I've posted it in moderated c++ as well, but it seems that it would be
an interest here as well, since someone says it is kind of optimizer
artifact.
The problem - unnamed/anonymous namespace makes the text segment
bigger. static is deprecated.
Using anonymous namespace makes the object size
bigger (gcc version 4.0.2 20051125 (Red Hat 4.0.2-8), FC4), and
unnecessary exported items in the link table. See the difference; it is
much bigger with anonymous namespace. Why is that? As far as I can see,
deprecating static would be the wrong thing to do.
e.g.:
#include <iostream>
#ifndef HAVE_STATIC
#define PUT_STATIC
#define PUT_NAMESPACE namespace{
#define END_NAMESPACE }
#else
#define PUT_STATIC static
#define PUT_NAMESPACE
#define END_NAMESPACE
#endif
PUT_NAMESPACE
PUT_STATIC int a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p;
PUT_STATIC int func1 () {return 1;}
PUT_STATIC int func2 () {return 2;}
PUT_STATIC int func3 () {return 3;}
PUT_STATIC int func4 () {return 4;}
PUT_STATIC int func5 () {return 5;}
PUT_STATIC int func6 () {return 6;}
PUT_STATIC int func7 () {return 7;}
END_NAMESPACE
int main(int, char**)
{
int x = a+b+c+d+e+f+g+h+i+j+k+l+m+n+o+p;
int y = func1()+func2()+func3()+func4()+func5()+func6()+func7();
return 0;
}
w/ namespace
% size ./a.out
text data bss dec hex filename
1774 308 72 2154 86a ./a.out
w/ static
size ./a.out
text data bss dec hex filename
1690 308 72 2070 816 ./a.out
- Anonymous namespace implications - footprints,
kobi . cohenarazi <=