A
ark
Hi,
If I got it right, C++ deprecates using 'static' keyword for internal
linkage in favor of a namespace.
I don't understand the equivalence though: namespace assignment does not
mechanically guarantee that the name won't be referenced (with proper scope
resolution) in another translation unit. So the compiler must treat the
namespaced function as if it had external linkage. Thus, it must miss on
several optimizations available for static functions, which may be possible
based on study of the use of the function. (Typical: partial
prologue/epilogue generation, automatic inlining and such, which in turn
allows further register optimization in the callers.)
E.g.,
static double foo(int x) { return (1-x*x*(x+1))/(double)(1+x*x); }
double bar(int y) { return (y<0)?foo(3):foo(5); }
In this case foo can be translated into something like
static double foo(int x)
{ return (x==3)?(1-3*3*4)/(double(10)1-5*5*6)/(double)(26); }
which is just a choice between two numbers.
Is this deprecation a concious sacrifice? If so, to what?
Thanks,
Ark
If I got it right, C++ deprecates using 'static' keyword for internal
linkage in favor of a namespace.
I don't understand the equivalence though: namespace assignment does not
mechanically guarantee that the name won't be referenced (with proper scope
resolution) in another translation unit. So the compiler must treat the
namespaced function as if it had external linkage. Thus, it must miss on
several optimizations available for static functions, which may be possible
based on study of the use of the function. (Typical: partial
prologue/epilogue generation, automatic inlining and such, which in turn
allows further register optimization in the callers.)
E.g.,
static double foo(int x) { return (1-x*x*(x+1))/(double)(1+x*x); }
double bar(int y) { return (y<0)?foo(3):foo(5); }
In this case foo can be translated into something like
static double foo(int x)
{ return (x==3)?(1-3*3*4)/(double(10)1-5*5*6)/(double)(26); }
which is just a choice between two numbers.
Is this deprecation a concious sacrifice? If so, to what?
Thanks,
Ark