The Static Keyword in C : No Longer Deprecated
In the evolution of the C standard, the usage of the static keyword within a translation unit underwent a significant change. Initially deprecated in n3092 and later removed in n3225, the use of static for declaring objects in namespace scope sparked confusion and debate.
The Rationale for Removal
The primary reason for the initial deprecation was the introduction of unnamed namespaces, which provided a cleaner and more explicit way of declaring objects with internal linkage. Unnamed namespaces offer several advantages, including easier management of global variables and avoiding potential name collisions.
The Reversal of Deprecation
However, in a later revision of the C Standard Core Language Defect Reports and Accepted Issues (revision 94), issue number 1012 titled "Undeprecating static" addressed the impracticality of fully removing support for the static keyword.
The Current Status
Despite its deprecation, static remains a valid and useful construct in C . It provides a concise and efficient method for declaring objects with internal linkage, especially in cases where the use of unnamed namespaces would result in unnecessary boilerplate code.
When to Use Static
The choice between static and unnamed namespaces depends on the specific requirements of the code. Static is still recommended for declaring functions or objects with internal linkage when the added complexity of unnamed namespaces is not warranted.
The above is the detailed content of Is the `static` keyword in C truly deprecated?. For more information, please follow other related articles on the PHP Chinese website!