I was reading a C reference about linkage (external, internal and none) and came across the following:
If, within a translation unit, the same identifier appears with both internal and external linkage, the behavior is undefined.
I wanted to know how this undefined behavior can occur. Based on what I had read, a variable can have only one storage class. So it cannot be declared both static
and extern
at the same time.
So in what scenario can a variable have both internal and external linkage?
In this code:
The first declaration says
x
has external linkage, and the second declaration says it has internal linkage.