When is static is deprecated?

V

Victor Bazarov

Jeffrey Schwab said:
Under what cicumstances is the keyword "static" (?:not)? deprecated?

IIRC, to declare a function for use only in the translation unit where
it's defined. The Standard recommends the use of anonymous namespace
for that. There is a difference there (static function has internal
linkage), but the result is basically the same: the symbol's name is
not known outside the translation unit.

Victor
 
J

Jeffrey Schwab

Victor said:
IIRC, to declare a function for use only in the translation unit where
it's defined. The Standard recommends the use of anonymous namespace
for that. There is a difference there (static function has internal
linkage), but the result is basically the same: the symbol's name is
not known outside the translation unit.

Victor

Thanks for the concise explanation!

So, even when I declare the internal functions of a module in an
anonymous namespace, they have external linkage? Do the extra,
externally linked symbols slow the typical linker? If so, is there any
non-deprecated way to declare functions that do *not* have external linkage?
 
V

Victor Bazarov

Jeffrey Schwab said:
Thanks for the concise explanation!

So, even when I declare the internal functions of a module in an
anonymous namespace, they have external linkage?
Yes.

Do the extra,
externally linked symbols slow the typical linker?

Not significantly, I'd think.
If so, is there any
non-deprecated way to declare functions that do *not* have external
linkage?

Not accessible from all scopes in a translation unit. You could define
an internal to a function class, members of that class don't have linkage
IIRC.

Victor
 
J

Jeffrey Schwab

Victor said:
Not significantly, I'd think.



linkage?

Not accessible from all scopes in a translation unit. You could define
an internal to a function class, members of that class don't have linkage
IIRC.

That's a good idea, but then those classes can't be arguments to
templates that are defined outside the function, right?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top