Sco*_*ott 2 c compiler-construction gcc header
希望这是一个直截了当的问题......这是我重现这个问题的过程.首先我创建我的源文件:
bash $ cat t.c
#include "t.h"
int main()
{
ABC abc;
}
Run Code Online (Sandbox Code Playgroud)
然后我创建相应的头文件:
bash $ cat t.h
#ifdef _T_H
#define _T_H
#ifdef __cplusplus
extern "C" {
#endif
typedef struct abc {
int a;
} ABC;
#ifdef __cplusplus
}
#endif
#endif
Run Code Online (Sandbox Code Playgroud)
然后,我尝试编译它:
bash $ gcc -o t t.c
t.c: In function ‘main’:
t.c:5: error: ‘ABC’ undeclared (first use in this function)
t.c:5: error: (Each undeclared identifier is reported only once
t.c:5: error: for each function it appears in.)
t.c:5: error: expected ‘;’ before ‘abc’
Run Code Online (Sandbox Code Playgroud)
到底是怎么回事?如果我使用'struct abc'而不是'ABC'作为tc中的类型,那么它会编译.为什么typedef不工作?
尝试:
#ifndef _T_H
#define _T_H
Run Code Online (Sandbox Code Playgroud)
我碰巧注意到这一点,因为_T_H没有排队,而我的潜意识大脑知道它应该.