-
Notifications
You must be signed in to change notification settings - Fork 183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should not care about endianness #55
Comments
Here is a very helpful public domain header file: https://gist.github.com/panzi/6856583 |
@fsateler what can be specifically done about this? |
@arielelkin I tried to do a patch for this but became quickly confused. Currently, stk has plenty of code of the following form: int value = read_from_somewhere();
#ifdef __LITTLE_ENDIAN__
swap32((unsigned char *)&value);
#endif Conditions vary depending on whether the file being read is little or big endian. The replacement using the linked gist header file, looks like this: int value = read_from_somewhere();
value = be32toh(value); The core point is that knowledge of the native endianness is not needed (in the linked file, only Windows needs such knowledge, ideally one would find another one that does not require even that): all that is needed is to know what format is being read/written from/to. Patch is not necessarily difficult, but requires a lot of care to not invert any given conversion. The advantage of not requiring this knowledge, is that every downstream project that allows bundling STK code can now drop the endian checks, which they probably do not need. |
@garyscavone any thoughts? |
If there are standard functions available on all supported platforms and OS’es to convert between host and big or little endian, then it would be nice to make this change. But if they only exist with the most modern versions of C++ and/or are not standard on all platforms and compilers (ex. Windows), then it should not be done.
|
@garyscavone Agreed. I think what is needed is a full set of conversions like the ones I quoted in the first post |
Most software does not need to care about native endianness, it just needs to convert to/from defined endianness to native when writing/reading, and that does not require actually knowing the native endianness.
From Rob Pike's blog:
That same post also heplfully describes how to read little or big endian 32 bit numbers:
LE:
i = (data[0]<<0) | (data[1]<<8) | (data[2]<<16) | (data[3]<<24);
BE:
i = (data[3]<<0) | (data[2]<<8) | (data[1]<<16) | (data[0]<<24);
However, it doesn't provide examples on how to write the numbers (which is likely the reverse of the above, but I need to verify first).
Not critical, but filing as an issue so that I don't forget.
The text was updated successfully, but these errors were encountered: