链接属性有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. "); void helper_sub_function(void) //link attribue is none { printf("It's helper sub function "); } }
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 }