ファイル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
このエラーに含めるcore.h
とmain.c
、tryがで定義されているため発生しませんcore.h
。しかし、私は構造try
を隠したいのですmain.c
—構造のメンバーを知っているべきではありませんtry
。私は何が欠けていますか?