3 c endianness
我正在阅读关于字节序的一些教程.得到了整数部分.但是,通过提及字节顺序问题是否也适用于C样式字符串而未提及正确答案的教程.endiannes是否适用于C样式字符串?根据我的理解,不,我是否正确?
例如,如果我有像这样存储的字符串"cap"
char: c a p \0
addr: 1000 1001 1002 1003
Run Code Online (Sandbox Code Playgroud)
说它写入文件.当来自不同endiannes的人阅读它时,我认为它应该仍然可以,不是吗?
小智 7
Endianness only applies to entities which are longer than one byte. Thus, narrow C strings which are arrays of char should be OK.
If you have wide strings, however, of type wchar_t[], then you should definitely be concerned about correctly handling endianness.