【发布时间】:2010-01-04 19:36:09
【问题描述】:
文件 api.h
#include <stdio.h>
#ifndef API
#define API
struct trytag;
typedef struct trytag try;
void trial (try *);
#endif
文件 core.h
#ifndef CORE
#define CORE
struct trytag
{
int a;
int b;
};
#endif
文件 func.c
#include "api.h"
#include "core.h"
void trial (try *tryvar)
{
tryvar->a = 1;
tryvar->b = 2;
}
文件 main.c
#include "api.h"
int main ()
{
try s_tryvar;
trial(&s_tryvar);
printf("a = %d\nb = %d\n", s_tryvar.a, s_tryvar.b);
}
当我编译时,我得到:
main.c:5: error: storage size of ‘s_tryvar’ isn’t known
如果我在main.c 中包含core.h,则不会出现此错误,因为在core.h 中定义了try。但我希望结构 try 隐藏到 main.c — 它不应该知道 try 结构的成员。我错过了什么?
【问题讨论】: