Compilation error in a very simple C struct
本问题已经有最佳答案,请猛点这里访问。
1 2 3 4 5 6 7 8  | typedef struct test {  int a; }; int main(void) { test t; t.a = 3; }  | 
在以上不编译。然而,当这两个变化:struct
1 2 3  | typedef struct { int a; }test;  | 
一切好的作品。这是为什么呢?在看过很多代码实例,在struct冰在相同的行为的类型,但它不是我编写的。
如果是一般的语法
1 2 3 4 5 6 7 8  |  typedef type-declaration      alias-name; | | | | | | typedef struct {int a; } test; //2nd one is correct | | | | typedef struct test { int a;} ; //You missed the synonym/alias name here  | 
编辑
在对国有企业postpischil埃里克
你只是把
参考文献:本
当你使用具有结构
如果你使用第一(《
你也可以使用相同的名称是《》和《
1 2 3  | typedef struct test {  int a; } test;  | 
我的工作与conceptualize 
1  | typedef"original type" "new type";  | 
(我知道这是不是100%准确,但它是一个有用的方式来查看它是简单的)
中的:
1 2  | typedef unsigned int HRESULT; // HRESULT is a new type that is the same as an unsigned int.  | 
在你的例子:
1  | typedef struct test { int a; }  (Missing Second Parameter!) ;  | 
你已经通过了第一个"停止",但你不
我想你想的是:
1  | typedef struct { int a; }  test;  | 
现在你已经采取的结构与单场(