In C , the static keyword within a translation unit determines the visibility of symbols. However, in n3092, its use for objects in namespace scope was deprecated, and in n3225, the deprecation was removed.
Curiously, documentation on this change is limited. This article delves into the reasons behind it.
In Revision 94 of C Standard Core Language Defect Reports and Accepted Issues, under 1012. Undeprecating Static, it states:
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.
In essence, the deprecation of static was misplaced. It provides a convenient way to declare functions or objects with internal linkage without requiring the boilerplate code of unnamed namespaces.
One concern was compatibility with C. However, compiling C programs as C can be challenging, so this factor may not have played a significant role.
The removal of the static keyword deprecation reflects the recognition that it remains a valuable feature in C . While unnamed namespaces offer an alternative, static provides a concise and direct solution for declaring objects or functions with internal linkage.
The above is the detailed content of Why Was the Deprecation of the Static Keyword in C Reversed?. For more information, please follow other related articles on the PHP Chinese website!