Home >Backend Development >C++ >Why Was the Deprecation of the Static Keyword in C Reversed?

Why Was the Deprecation of the Static Keyword in C Reversed?

Linda Hamilton
Linda HamiltonOriginal
2024-11-27 12:31:10447browse

Why Was the Deprecation of the Static Keyword in C   Reversed?

Deprecation of the Static Keyword: A Reconsideration

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.

Rationale for Removal

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.

Legacy Concerns

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.

Conclusion

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn