No linkage at block scope?

后端 未结 2 1962
时光说笑
时光说笑 2021-02-20 06:25

Do all variables declared in a block have \'no linkage\'?

For example:

1:

If I declare a static variable:

void foo()
{
   static int i;         


        
2条回答
  •  逝去的感伤
    2021-02-20 06:50

    1. "Would it have internal linkage or no linkage? if no linkage then why make it static?" -- it would have no linkage. static specifies the static storage duration.

    2. "What happens if i use extern?" It will be a declaration of a name with external linkage, and since there is none in global scope, the program will report linkage errors. Edit: Since there is a previous static declaration visible in the scope, the standard says the name "receives the linkage of the previous declaration" 3.5/6, so the i inside foo() will have internal linkage.

提交回复
热议问题