Topic: Inconsistency with linkage of const variables


Author: Trevor Yann <TYann@vet.com.au>
Date: 1997/09/11
Raw View
Const variables have internal linkage by default. (I am referring to
"file level" constants here - those declared outside of a class or
function). All other declarations default to external linkage.

Currently constants with external linkage can be declared in multiple
translation units, but must be defined in a single translation unit. In
order to reduce incompatibilities with existing programs, the definition
would have to become optional (or deemed to be deprecated).

Historically constants defaulted to internal linkage to allow them to be
declared in header files. If const variables had external linkage, this
would have required the langauage implementation to resolve definitions
in multiple translation units.

Inline functions now default to external linkage - to specify internal
linkage, the function must be declared "static". It would be consistent
to treat constants the same way. Constants are analogous to inline
functions - the "value" of an inline function is known (the function
body), and the "value" of a constant is also known.


It appears that the current rule is a grtuitous inconsistency in the
language.
---
[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]