我想知道可以用#define分配unsigned char吗?

例如:

 #define ACCESS_PSS {0x32,0xFD,0x6E,0x2D}


    int main(){
    unsigned char ResponseData[100];
    for (int i = 0; i <4;i++0){

                    if (ResponseData[i+5]==ACCESS_PSS){ //how to do this???
                                cout<<5<<endl;
                                              }


ResponseData从程序获取值,字节5 ta 8等于ACCESS_PSS

最佳答案

最好的办法:

const uint8_t ACCESS_PSS [4] = {0x32,0xFD,0x6E,0x2D};

if(memcmp(&ResponseData[i+5], ACCESS_PSS, 4) == 0)


替代方式(复合文字):

if(memcmp(&ResponseData[i+5], (uint8_t[4]){0x32,0xFD,0x6E,0x2D}, 4) == 0)

关于c++ - 如何用无符号字符分配#define,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30887075/

10-14 08:03