Troubles with enum...

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

Troubles with enum...

跳至解决方案
4,104 次查看
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
标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,570 次查看
ThomasH
Contributor II

Thanks for your helps!

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

在原帖中查看解决方案

0 项奖励
回复
3 回复数
1,570 次查看
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 项奖励
回复
1,571 次查看
ThomasH
Contributor II

Thanks for your helps!

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

0 项奖励
回复
1,570 次查看
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 项奖励
回复