cstaticlinkagestorage-class-specifier

Whether Global Variables in C, static or extern?


I just started learning C programming. In some of the books and web articles, I could find that any Global Variable in C by default corresponds to static storage class but has external linkage. Does this mean it is partially static and partially extern? Because as per my understanding any global variable with static storage class specifier has internal linkage only and can be accessed within the same file.

P.S: I referred this question Global variables in C are static or not? , but could not get really whether Global variables are static or extern by default in C.


Solution

  • Global Variable in C by default corresponds to static storage class but has external linkage. Does this mean it is partially static and partially extern?

    The English word “static” has muddled and multiple meanings in C, and, yes, the default for a variable declared outside a function is to have static storage duration and external linkage.

    Because there are multiple concepts here and some mixed use of word meanings, we should clarify some terminology and formatting:

    The English word “static” generally means unchanging. The C standard uses this word and the keyword static in multiple ways:

    These multiple uses are unfortunate and are due at least partly to the history of how the C language was developed.