【发布时间】:2015-10-21 14:16:44
【问题描述】:
考虑以下程序:(参见现场演示here)。
#include <stdio.h>
struct Test
{
int a;
};
typedef struct Test t;
typedef struct Test t;
int main()
{
t T={9};
printf("%d",T.a);
}
程序在 C11 编译器中编译良好,但在 C99 编译器中编译失败。为什么?是什么原因? 我的编译器 gcc 4.8.1 给出以下警告:
[Warning] redefinition of typedef 't' [-Wpedantic]
[Note] previous declaration of 't' was here
【问题讨论】:
-
编译器是给你提示还是拒绝编译而不产生任何错误信息?
-
@PravasiMeet 我没有,因为我今天没有任何选票,但可能是因为您的问题不够彻底,并且您遇到的错误丢失了。
-
有趣。你想对这些警告/错误保密吗?或者你能和我们分享一下吗?
-
养成包含来自编译器/链接器的任何错误/警告消息的习惯。
-
@PravasiMeet 如果有的话,抱怨反对票会吸引更多人。你的问题是否表明研究和努力是由社区决定的,而不是你。