I'm trying to understand linkage of enumeration constant
s and could not find a clear answer in the Standard N1570
. 6.2.2(p6)
:
The following identifiers have no linkage: an identifier declared to be anything other than an object or a function; an identifier declared to be a function parameter; a block scope identifier for an object declared without the storage-class specifier
extern
.
So I need to understand that constants are not objects. Object is defined as 3.15
:
region of data storage in the execution environment, the contents of which can represent values
Also 6.2.2(p4)
(emphasize mine):
For an identifier declared with the storage-class specifier extern in a scope in which a prior declaration of that identifier is visible,31) if the prior declaration specifies internal or external linkage, the linkage of the identifier at the later declaration is the same as the linkage specified at the prior declaration. If no prior declaration is visible, or if the prior declaration specifies no linkage, then the identifier has external linkage.
Anyway 6.4.4.3(p2)
:
An identifier declared as an enumeration constant has type
int
.
Combining all that I don't understand why
enum test {
a = 1
};
extern int a; //compile-error. UB?
does not compile? I expected a
to have external linkage.
Is the behavior well-defined? Can you provide a reference to the Standard explaining that?
int a; extern int a;
why this do not compile. It is exactly the same two same symbols in one compilation unit. It does not have anything in common with the linkage. – 0___________123
and character constants'A'
. – Lundin