#const variables internal linkage

5 messages · Page 1 of 1 (latest)

round marlin
#

why do const variables have internal linkage?

outer dragonBOT
#

When your question is answered use !solved or the button below to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

pallid wharf
#

So you can define constants in header files without violating ODR.

When you include that header file in many .cpp files, it’s local to the current translation unit (basically, the .cpp file thats being compiled + all its included headers)
Afaik C++17(11?14?) introduces a new meaning for inline that indicates to the linker that an identifier is allowed to be defined in multiple translation units and that the definition will be the same everywhere.

Const variables are implicitly inline

unborn jetty
#

Internal linkage and inline refer to different concepts. Internal linkage refers to stuff like static globals

#

Anyway, it's just too prevent bugs, and it's not like you would need external linkage of a read only variable.