user195488
user195488

Reputation:

Unable to use extern and static storage-class specifiers together

In C99 6.7.1 it says

At most, one storage-class specifier may be given in the declaration specifiers in a declaration

I know extern and static are both storage class specifiers but extern basically states to the compiler that the variable is declared elsewhere and worry about it later. extern and static to me are NOT mutually exclusive. It is very well possible that something could be extern and static.

Why can't we use extern and static together? Is there a good reason other than the standard simply says, no?

Upvotes: 1

Views: 1135

Answers (2)

Alok Save
Alok Save

Reputation: 206528

Well, static means Internal Linkage, extern means External Linkage.

Internal Linkage refers to everything only in scope of a Translation unit.

External Linkage refers to things that exist beyond a particular translation unit. In other words, accessable through the whole program.

So both are mutually exclusive.

Upvotes: 5

Jens
Jens

Reputation: 6329

"Static" outside all blocks means "internal linkage", "extern" means external linkage. What should static extern mean? Internal external linkage???

Upvotes: -2

Related Questions