3

I was reading some tutorial on endianness. Got the integer part. But the tutorial left of by mentioning whether endianness issues apply also for C style strings, without mentioning correct answer. Does endiannes apply to C style strings? From my understanding, No. am I correct?

e.g., if I have string "cap" stored like this

char:    c    a    p   \0
addr: 1000 1001 1002 1003

Say it is written to file. When someone from a different endiannes reads it, I think it should still be ok, isn't it?

4

1 回答 1

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.

于 2013-10-08T08:19:53.257 回答