Simultaneously creating internal and external linkages in C

114 views Asked by At

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?

1

There are 1 answers

4
Eric Postpischil On BEST ANSWER

In this code:

extern int x;
static int x;

The first declaration says x has external linkage, and the second declaration says it has internal linkage.