c++ - #define as unsigned char -
i know how can tell compiler #define
unsigned char
. if #define
1 byte this:
#define aaceess_pss 0x80 #define access_pss ((unsigned char)0x80)
but if #define
has more byte should do?? example:
#define access_pss {0x32,0xfd,0x6e,0x2d}
i need cast assign #define
unsigned char
int main(){ unsigned char responsedata[100]; (int = 0; <4;i++0){ if (responsedata[i+5]==access_pss){ //how this??? cout<<5<<endl; }
responsedata
programm value , byte 5 8 equal access_pss
.
responsedata[i+5]==access_pss
you can't compare 4 unsigned chars
single equality operator in c.
you can convert uint32_t, may break due unaligned access or different endianness, i.e.:
#define access_pss 0x32fd6e2d ... if(*((uint32_t*) (responsedata + + 5)) == access_pss) { /*...*/ }
the clean way memcmp
, or similiar function:
const unsigned char access_pss[4] = {0x32,0xfd,0x6e,0x2d}; ... if(memcmp(responsedata + + 5, access_pss, 4) == 0) { /*...*/ }
Comments
Post a Comment