"Accidental" forward declaration of enum without compiler warning?

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

"Accidental" forward declaration of enum without compiler warning?

ソリューションへジャンプ
2,249件の閲覧回数
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,083件の閲覧回数
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,084件の閲覧回数
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 件の賞賛
返信