main.c
#include<stdio.h>
#include "type.h"
#include<stdlib.h>
struct t g;
int k;
int main()
{
strcpy(g.name,"gff");
printf("%s\n",g.name);
foo();
}
foo.c
#include<stdio.h>
#include "type.h"
int k=0;
void foo(void)
{
printf("hello struct boy\n");
}
type.h
#ifndef _TYPE_H_
#define _TYPE_H_
int m;
struct t{
char name[5];
};
extern void foo();
#endif
上面是编译通过的
在gnu下 在多个文件中可以定义一个变量,但是不能同时赋值,这样会编译报错