本文共 337 字,大约阅读时间需要 1 分钟。
写个头文件 c.h 声明 一个结构体类型 struct STU { int x; int y; }; 定义结构体变量s的文件b.c #include "c.h" struct STU s; /* 不加extern ,默认认为extern */ a.c 调用b.c里定义的全局变量s #include#include "c.h" /* struct STU这个类型的定义(或者说声明)在这个头文件里 */ extern struct STU s;/* 声明它是外部的类型是struct STU */ int main() { printf("s.x+s.y = %d+%d = %d\n",s.x,s.y,s.x+s.y);/*调用了*/ }
转载地址:http://wrhxi.baihongyu.com/