Troubles with enum...

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

Troubles with enum...

ソリューションへジャンプ
4,115件の閲覧回数
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,581件の閲覧回数
ThomasH
Contributor II

Thanks for your helps!

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

元の投稿で解決策を見る

0 件の賞賛
返信
3 返答(返信)
1,581件の閲覧回数
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,582件の閲覧回数
ThomasH
Contributor II

Thanks for your helps!

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

0 件の賞賛
返信
1,581件の閲覧回数
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 件の賞賛
返信