Closed mgerhardy closed 5 months ago
This shouldn't be necessary since the code reads in one byte at a time, thanks for the idea though!
Sorry, I suppose I don't understand. Why shouldn't this be needed? You are reading byte by byte and bit shifting the value into the little endian representation.
value = (*p)[0];
value |= (((uint16_t)((*p)[1])) << 8);
as far as I know this is incorrect for big endian systems and should get swapped.
Thanks for asking, the bitshifting is platform independent. If you study the C standard you can see that the bitshifting itself will place the bytes into the correct endian format. The strategy here is to intentionally only read in only one byte and rely on the bitshifting to handle reading-endianness.
Thanks a lot for clarification
When using SDL you could e.g. use
or the gcc built-ins like
__builtin_swap32
, ... to perform the byte swapping