Code warrior does not recognize global structure variable

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

Code warrior does not recognize global structure variable

1,300 次查看
jaehak9708
Contributor II

Hi,

I'm using code warrior IDE version 5.9.0 for MPC55xx/56xx. 
pastedImage_1.png

According to my preference setting, the global variables should be purple. 

I declared the struct variable such as , 

// aaa.h

struct _A

{

   uint8_t a:1;

   uint8_t b:1;

   uint8_t :6;

}

void floor(void);

#ifdef _aaa_h_

  struct _A a_struct;

#else

  extern struct _A a_struct;

#endif

// aaa.c

#include "aaa.h"

void floor(void)

{

  a_struct.a = 1;

}

I think that the struct variable 'a_struct' will be purple. But it doesn't. Its color is white (foreground).

There is no compile error. 

When I declare the struct variable in main.h and main.c, It works, 

But in other source, header files, It doesn't apply. 

Is It just a bug? 

标签 (1)
2 回复数

1,231 次查看
ErichStyger
Specialist I

Somewhat probably unrelated, but:

You have this:

#ifdef _aaa_h_

  struct _A a_struct;

#else

  extern struct _A a_struct;

#endif

which is very unusual and even very dangerous: you never should have variable definitions in header files except you know exactly what you are doing. Because depending on that define and potentially include orders you will have multiple definitions. What you really should have is

extern struct _A a_struct;

in aaa.h

and

struct _A a_struct;

in aaa.c.

As a positive side effect, I guess your coloring thing will go away too.

I hope this helps,

Erich

1,231 次查看
jaehak9708
Contributor II

You are right, Thank you :smileyhappy:

Regards, 

Jaehak Kim