我希望一些共享变量应该在源文件main.c和secondary.c之间访问,我的头文件是all.h定义了共享数据类型,
#ifndef ALL_H
#define ALL_H
struct foo {
double v;
int i;
};
struct bar {
double x;
double y;
};
#endif
Run Code Online (Sandbox Code Playgroud)
main.c如下
/* TEST*/
#include "all.h"
#include "second.h"
int main(int argc, char* argv[])
{
struct foo fo; // should be accessed in second.c
fo.v= 1.1;
fo.i = 12;
struct bar ba; // should be accessed in second.c
ba.x= 2.1;
ba.y= 2.2;
sec(); // function defined in second.c
return 0;
}
Run Code Online (Sandbox Code Playgroud)
下面给出了secondary.h
#include …Run Code Online (Sandbox Code Playgroud) c ×1