Why won't extern link to a static variable?

前端 未结 4 570
离开以前
离开以前 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:11

    iv.c:2:1: error: multiple storage classes in declaration specifiers extern static int i; ^

    That is what we get on attempting to extern a static variable. Declaring extern static int i; - is analogous to the declaration float int i; You can't have float and int appear in the same declaration right? Similarly, you can't have extern and static in the same declaration.

提交回复
热议问题