开发者

how to use #define to access struct members in c

I have following 开发者_Go百科struct defination:

typedef union U08_16_t  
 { 
   unsigned long s32;//message32
   unsigned char sb32[4];//message_bytes1
 }b32;

 struct t72
 {
   unsigned char  HH;
   b32 wH;
   b32 wL;
 };


 #define MfrCode        TCDU.wL.sb32[2];
 #define subclass   TCDU.wH.sb32[3];
 #define MRF  34

 extern struct t72 xdata TCDU;

now later in the code, after getting some values into the struct variable TCDU, i'm trying to compare the value of MfrCode (which is #defined as TCDU.wL.sb32[2]), with the constant MRF which is defined as 34 above, but i'm getting an error on that line of code:

    ...

if(MRF != MfrCode)
    return FALSE;
    ...

i'm not sure why, can any one help me with this.


You need to get rid of the semicolons in your #defines - change:

#define MfrCode    TCDU.wL.sb32[2];
#define subclass   TCDU.wH.sb32[3];
#define MRF  34

to:

#define MfrCode    TCDU.wL.sb32[2]
#define subclass   TCDU.wH.sb32[3]
#define MRF  34
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜