在确保翻译单元之间的可用性时是否弃用静态?
Is static deprecated when ensuring availability between translation units?
来自以下Whosebug answer,用户说:
It means that the variable is local to a translation unit (simply put,
to a single source file), and cannot be accessed from outside it. This
use of static is in fact deprecated in the current C++ Standard -
instead you are supposed to use anonymous namespaces:
static int x = 0;
should be:
namespace {
int x = 0;
}
我不同意匿名命名空间是首选方法,
但是现在真的不推荐使用 static 了吗?
标准哪里这么说的?
不,目前尚未弃用。它曾一度出现,但由于 C 语言的可比性问题而被逆转。在 1999 年之前的某个时候它被弃用了,这导致 defect report 174 说:
The decision to deprecate global static should be reversed.
- We cannot deprecate static because it is an important part of C and to abandon it would make C++ unnecessarily incompatible with C.
- Because templates may be instantiated on members of unnamed namespaces, some compilation systems may place such symbols in the
global linker space, which could place a significant burden on the
linker. Without static, programmers have no mechanism to avoid the
burden.
这导致 defect report 223 其中 弃用 的含义修改自:
deprecated is defined as: Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions.
有人指出,这意味着未来的标准将只支持未弃用的功能:
However, this definition would appear to say that any non-deprecated feature is "guaranteed to be part of the Standard in future revisions." It's not clear that that implication was intended, so this definition may need to be amended.
并将弃用的含义更改为:
These are deprecated features, where deprecated is defined as: Normative for the current edition of the Standard, but having been identified as a candidate for removal from future revisions.
后来,由于 defect report 1012:
的 C 兼容性问题,该功能不再被弃用
Although 7.3.1.1 [namespace.unnamed] states that the use of the static keyword for declaring variables in namespace scope is deprecated because the unnamed namespace provides a superior alternative, it is unlikely that the feature will be removed at any point in the foreseeable future, especially in light of C compatibility concerns. The Committee should consider removing the deprecation.
来自以下Whosebug answer,用户说:
It means that the variable is local to a translation unit (simply put, to a single source file), and cannot be accessed from outside it. This use of static is in fact deprecated in the current C++ Standard - instead you are supposed to use anonymous namespaces:
static int x = 0;
should be:
namespace { int x = 0; }
我不同意匿名命名空间是首选方法,
但是现在真的不推荐使用 static 了吗?
标准哪里这么说的?
不,目前尚未弃用。它曾一度出现,但由于 C 语言的可比性问题而被逆转。在 1999 年之前的某个时候它被弃用了,这导致 defect report 174 说:
The decision to deprecate global static should be reversed.
- We cannot deprecate static because it is an important part of C and to abandon it would make C++ unnecessarily incompatible with C.
- Because templates may be instantiated on members of unnamed namespaces, some compilation systems may place such symbols in the global linker space, which could place a significant burden on the linker. Without static, programmers have no mechanism to avoid the burden.
这导致 defect report 223 其中 弃用 的含义修改自:
deprecated is defined as: Normative for the current edition of the Standard, but not guaranteed to be part of the Standard in future revisions.
有人指出,这意味着未来的标准将只支持未弃用的功能:
However, this definition would appear to say that any non-deprecated feature is "guaranteed to be part of the Standard in future revisions." It's not clear that that implication was intended, so this definition may need to be amended.
并将弃用的含义更改为:
These are deprecated features, where deprecated is defined as: Normative for the current edition of the Standard, but having been identified as a candidate for removal from future revisions.
后来,由于 defect report 1012:
的 C 兼容性问题,该功能不再被弃用Although 7.3.1.1 [namespace.unnamed] states that the use of the static keyword for declaring variables in namespace scope is deprecated because the unnamed namespace provides a superior alternative, it is unlikely that the feature will be removed at any point in the foreseeable future, especially in light of C compatibility concerns. The Committee should consider removing the deprecation.