C developers have long utilized the 'static' keyword within translation units to control symbol visibility. However, this practice garnered a deprecation in n3092, followed by its removal in n3225.
The deprecation of 'static' aimed to discourage its use for declaring objects in namespace scope, as the unnamed namespace offered a preferable alternative. However, the issue tracking C defects reveals a nuanced reason for this change.
In Revision 94 of the C Standard Core Language Defect Reports, the issue (1012. Undeprecating static) explains that:
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.
This update effectively reverses the deprecation. 'Static' remains a valid keyword for declaring functions and objects with internal linkage. Its primary advantage lies in its brevity and lack of additional boilerplate code compared to using unnamed namespaces.
The original deprecation aimed to enhance C 's adherence to C standards, as C does not recognize the unnamed namespace. However, the decision to rescind the deprecation acknowledges the real-world complexities of compiling C programs as C .
The deprecation of 'static' may have been well-intentioned, but its removal reflects the realization that unnamed namespaces do not fully replace the utility of 'static' for declaring objects with internal linkage. As a result, developers can continue to use 'static' with confidence, as its presence in the C standard is unlikely to fade anytime soon.
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!