Home > Backend Development > C++ > Is the 'static' keyword in C truly deprecated?

Is the 'static' keyword in C truly deprecated?

DDD
Release: 2024-11-13 07:23:02
Original
912 people have browsed it

Is the 'static' keyword in C   truly deprecated?

Internal Linkage and the Deprecated 'static' Keyword in C

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 Rationale for Deprecation

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.

The Rescission of Deprecation

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.

The Persistence of 'static'

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.

Implications for C and C Compatibility

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 .

Conclusion

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!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template