"Accidental" forward declaration of enum without compiler warning?

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

"Accidental" forward declaration of enum without compiler warning?

跳至解决方案
2,220 次查看
CodeMonkey
Contributor I
Hi,
 
I am running CodeWarrior IDE 5.7.0 Build 2211 with an S12XE processor.
 
Consider this code:
 
enum MyEnumDef { ALARM, SHUTDOWN };
 
struct MyStructDef {
  enum MyEnumDefS MyEnumDeclaration;
};
 
struct MyStructDef MyStructDeclaration;
 
and later in the code in a function:
 
MyStructDeclaration.MyEnumDeclaration = ALARM;
 
Please note the typo when declaring MyEnumDeclaration within the struct! The compiler eats this without any complaint. Why is that? It seems like it does not matter how I declare the enum within the struct. I can declare it as "yadiyadiblabla" and the compiler does not care. Same code in Code Composer produces a "Forward declaration of enum type is non-standard" warning. Is this expected behavior?
 
Thanks,
Chris
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,054 次查看
CompilerGuru
NXP Employee
NXP Employee
A warning would be nice to have, but the ANSI-C standard is rather relaxed about enums :smileysad:.
That's one of the places C++ is more strict in its type system.

Daniel

在原帖中查看解决方案

0 项奖励
回复
1 回复
1,055 次查看
CompilerGuru
NXP Employee
NXP Employee
A warning would be nice to have, but the ANSI-C standard is rather relaxed about enums :smileysad:.
That's one of the places C++ is more strict in its type system.

Daniel
0 项奖励
回复