Home >Backend Development >C++ >Why Does `const` Imply Internal Linkage in C but External Linkage in C?

Why Does `const` Imply Internal Linkage in C but External Linkage in C?

DDD
DDDOriginal
2024-12-02 17:01:11672browse

Why Does `const` Imply Internal Linkage in C   but External Linkage in C?

Why Const Implies Internal Linkage in C , but Not in C

In C , the 'const' keyword denotes a constant variable or object. Contrary to C, in C , declaring a constant at namespace scope implies internal linkage rather than external linkage.

Appendix C (C 11, C.1.2) provides the reasoning behind this distinction:

"A name of file scope that is explicitly declared const, and not explicitly declared extern, has internal linkage, while in C it would have external linkage."

This modification was introduced to encourage explicit initialization values for constant objects, leveraging their use as compile-time values in C . By allowing the placement of const objects in header files included in multiple compilation units, this feature enhances code organization.

The above is the detailed content of Why Does `const` Imply Internal Linkage in C but External Linkage in C?. 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