Troubles with enum...

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

Troubles with enum...

Jump to solution
3,490 Views
ThomasH
Contributor II
 
I´m a newbie in programming with CodeWarrior and I´m porting software from my old compiler to the CodeWarrior and I faced a very confusing problem:
 
I had defined the structure:
 
typedef struct
{
   BYTE menu_nr_left;          
   BYTE menu_nr_right;
   BYTE menu_nr_up;  
   .....
   enum 
   {
     NUMBER=0,                        
     TEXT_1=1,                        
     TEXT_2=2                        
   }para_view:2;                   
  
   unsigned int txt_idx;       
   .....
}view_tab_t;
 
During compiling of the sources I get the error message that NUMBER, TEXT_1 and TEXT_2 are not declared. All declarations in this header are working fine except all enum´s. Please can anybody tell me, what I´ve done wrong?
 
Thanks in advance!
Thomas
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
956 Views
ThomasH
Contributor II

Thanks for your helps!

I defined all enums outside the struct and now all works!

View solution in original post

0 Kudos
Reply
3 Replies
956 Views
blewis
Contributor I
I have encountered the same thing with array definitions using constants defined using enum. The best way is to place the enum definitions in a separate file to give them file scope.
0 Kudos
Reply
957 Views
ThomasH
Contributor II

Thanks for your helps!

I defined all enums outside the struct and now all works!

0 Kudos
Reply
956 Views
CrasyCat
Specialist III

Hello

I assume you are using CodeWarrior for HC12 V4.5. Am I right?

Basically the constants NUMBER, TEXT_1 and TEXT_2  are defined in type view_tab_t. They do not have global scope and are not available outside of a variable of type  view_tab_t.

If you wish to test against that constant you have to write:

  if (viewTab.para_view == viewTab.TEXT_2) {

where viewTab is defined as

view_tab_t viewTab;

Another alternative to to define the enumerated type and its constant outside of the structured type view_tab_t.

CrasyCat

0 Kudos
Reply