Why won't extern link to a static variable?

前端 未结 4 593
离开以前
离开以前 2020-11-29 16:51

Why does extern int n not compile when n is declared (in a different file) static int n, but works when declared int n? (Both of thes

4条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 17:01

    According to MSDN documentation:

    When modifying a variable, the static keyword specifies that the variable has static duration (it is allocated when the program begins and deallocated when the program ends) and initializes it to 0 unless another value is specified. When modifying a variable or function at file scope, the static keyword specifies that the variable or function has internal linkage (its name is not visible from outside the file in which it is declared).

    http://msdn.microsoft.com/en-us/library/s1sb61xd(v=vs.80).aspx: June 2013

提交回复
热议问题