C语言和指针-回顾03-链接属性:external,static,none

时间:2021-06-28 20:22:08   收藏:0   阅读:0

链接属性有external,internal,none。

关键字extern和static用于在生命中修改标识符的链接属性。

某个声明在默认的情况下是具有external属性的,前面追加static可以让它的属性变为internal。

 

helper.c:

#include<stdio.h>

int helper_global_variable;
static int helper_static_variable;
void helper_sub_function(void);
void helper_function(void)
{
    int helper_local_variable;      //link attribue is none
    printf("It‘s helper function.\n");
    void helper_sub_function(void)  //link attribue is none
    {
        printf("It‘s helper sub function\n");
    }
}

 

 

main.c:

#include<stdio.h>

extern int helper_global_variable;
extern int helper_static_variable;
extern void helper_function(void);
extern void helper_sub_function(void);
int main(void)
{
    helper_global_variable = 1;     // link attribute is external
    //helper_static_variable = 2;   //link attribute is status, so cannot access it
    helper_function();              // link attribute is external
    //helper_sub_function();        //link attribue is none, so cannot access it
}

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!