【发布时间】:2011-01-15 15:35:49
【问题描述】:
在给定的代码 sn-p 中,我预计会出现错误 symbol Record not found。但它在 Visual Studio 2010 编译器上编译并运行良好。我以 C 程序从 Visual Studio 2010 命令提示符中运行它 -
cl Record.c
记录
现在的疑问是,typedef 不检查符号吗?它更像forward declaration 吗?
#include "stdio.h"
#include "conio.h"
typedef struct Record R;
struct Record
{
int a;
};
int main()
{
R obj = {10};
getch();
return 0;
}
【问题讨论】:
-
试着把
typedef struct Record R;放在struct Record ...下面 -
@xhan - 如果我这样做,它是有意义的,因为符号
Record更早被发现。谢谢。 -
您的代码在 GCC(必须将 getch 更改为 getchar)和 VS2005 下运行良好。我怀疑你的发现是正确的。