我有3个文件。在一个文件中,我宣布一个结构,其中有主要的另一个文件,我想使用的extern关键字--------如何使用'c'语言使用extern关键字访问在其他文件中声明的结构
//a.c---
include<stdio.h>
extern struct k ;
extern int c;
int main()
{
extern int a,b;
fun1();
fun2();
c=10;
printf("%d\n",c);
struct k j;
j.id=89;
j.m=43;
printf("\n%d\t%f",j.id,j.m);
}
//1.c
#include<stdio.h>
struct k
{
int id;
float m;
}j;
int c;
void fun1()
{
int a=0,b=5;
printf("tis is fun1");
printf("\n%d%d\n",a,b);
}
//2.c--
#include<stdio.h>
struct k
{
int id;
float m;
}j;
void fun2()
{
int a=10,b=4;
printf("this is fun2()");
printf("\n%d%d\n",a,b);
}
访问结构我用cc a.c 1.c 2.c
编译的代码但我得到错误为storage size of ‘j’ isn’t known
请更改标签。这与c# – Nissim 2010-08-26 06:56:08