Reading “integer” size bytes from a char* array.

前端 未结 9 1274
深忆病人
深忆病人 2020-12-09 05:13

I want to read sizeof(int) bytes from a char* array.

a) In what scenario\'s do we need to worry if endianness needs to be checked?

9条回答
  •  一整个雨季
    2020-12-09 05:40

    Do you mean something like that?:

    char* a;
    int i;
    memcpy(&i, a, sizeof(i));
    

    You only have to worry about endianess if the source of the data is from a different platform, like a device.

提交回复
热议问题