Quote:Original post by Troll
Quote:Original post by Mxz
static variables at namespace scope are deprecated in C++. const variables have internal linkage by default. You can verify this with the following code.
static variables are deprecated, but that's irrelevant for two reasons:
1) They're deprecated in favor of, of all things, globals. Namespace-scoped statics are deprecated in favor of globals in unnamed namespaces. They're fairly (but not completely) identical.
2) Even without #1, they'll never be removed because they're too prevalent in pre-existing code.
I'm a big fan of namespace-level statics or #1 now that they are deprecated. They're much preferable to a private class static. If it's a private static, it's an implementation detail, and I'd rather not change a header file when I change an implementation detail.
I don't think you are correct to say that a deprecated feature will never be removed, for the very reason that the definition of the word deprecated in C++ is: Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions.
If they had no intention of removing it then they would not have made it deprecated, but if you wish to carry on using it, that is your prerogative. I think it is also worth stating explicitly that use of the static keyword is only deprecated when declaring objects in namespace scope, your post seemed to confuse that slightly.
However, I do agree that static namespace scoped variables being deprecated is largely irrelevant to this discussion (assuming that is what you meant). I used it merely as an example of why the static keyword is not needed to give a variable internal linkage, and hence give the translation unit conceptual ownership of that 'global' variable.