Will a char array differ in ordering in a little endian or big endian system

前端 未结 4 879
[愿得一人]
[愿得一人] 2021-02-02 03:11

I have an array char c[12] = {\'a\',\'b\',\'c\',\'d\',\'e\',\'f\',\'g\',\'h\',\'0\',\'1\',\'2\',\'3\'} In hexadecimal these values would be {0x61, 0x62, 0x63,

4条回答
  •  独厮守ぢ
    2021-02-02 03:54

    The char/byte is, by definition, the smallest addressable unit of memory. Consequently, there is no meaningful concept of "endianness" within a single byte, because the processor cannot index inside it; it can only read the whole thing. Individual bits from within a byte are obtained by mathematical operations, not by addressing; their physical location has nothing to do with how they're read. Endianness only refers to multi-byte objects that have indexable, and thus physically-ordered, subcomponents.

    By definition an array has elements in only one order, otherwise indexing operations would fail, so the machine's notions of endianness for larger types that could hypothetically occupy the same space are not relevant to it either, as they would destroy the array's access rules.

提交回复
热议问题