search

Home  >  Q&A  >  body text

c++ - 对一块连续内存取地址,大小端会对其造成影响么?

也就是对于同一块连续的内存,在小端模式下输出其地址,和,在大端模式下输出其地址,这两个地址一样么?如果一样,那都是低地址么?还是.....

-------------------------------补充------------------------
数据地址的存储方向因为大小端会有不同,这我知道,我想知道的是,是否会因为大小端,造成在取一段连续内存的地址时,输出不同呢?比如说,一个输出了该段内存的低地址,另一个输出了高地址?

高洛峰高洛峰2767 days ago817

reply all(4)I'll reply

  • 迷茫

    迷茫2017-04-17 15:37:36

    1. Whether it is big endian mode or little endian mode, the output address is the same.

    2. All low addresses are returned.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 15:37:36

    Both are low addresses
    Big and small endianness only affects the parsing order and not the address

    reply
    0
  • 黄舟

    黄舟2017-04-17 15:37:36

    Give you an example, if you want to save 0x12345678 to 0x10000000,
    In little endian mode:
    0x78 exists 0x10000000
    0x56 exists 0x10000001
    0x34 exists 0x10000002
    0x12 exists 0 x10000003
    In big endian mode:
    0x12 exists as 0x10000000
    0x34 exists as 0x10000001
    0x56 exists as 0x10000002
    0x78 exists as 0x10000003

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 15:37:36

    This is an x86 machine, little endian, I don’t know if you understand it. Let me explain a little bit, the address of a is 0x4007cd, a single byte is printed in sequence as cd 07 40 00, two bytes are printed as 07cd 0040, and four bytes are printed as 004007cd, so the big and small ends are correct It doesn't matter from the upper level. If it is at the assembly level, it is still very obvious. For example, mov al, ah and the like have to consider the issue of big and small endianness.

    reply
    0
  • Cancelreply