Header file and extern keyword

前端 未结 5 2046
青春惊慌失措
青春惊慌失措 2021-01-22 21:06

I am having a lot of issue using extern variable and header files. I have read through sections of books and searched the web for hours but I haven\'t been able to figure out. A

5条回答
  •  迷失自我
    2021-01-22 21:15

    gI must be declared above main:

    int gI = 0;
    
    int main(void)
    {
        ...
    }
    

    By doing this gI has file scope and external linkage.

    Perhaps a better place to declare gI would be in sample.c, if there is such a file.

提交回复
热议问题