"Accidental" forward declaration of enum without compiler warning?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

"Accidental" forward declaration of enum without compiler warning?

Jump to solution
2,222 Views
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
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,056 Views
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

View solution in original post

0 Kudos
Reply
1 Reply
1,057 Views
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 Kudos
Reply