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

前端 未结 9 1275
深忆病人
深忆病人 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:26

    Depends on how you want to read them, I get the feeling you want to cast 4 bytes into an integer, doing so over network streamed data will usually end up in something like this:

    int foo = *(int*)(stream+offset_in_stream);
    

提交回复
热议问题