Why is a double member in struct not aligned on 8 byte boundary?

前端 未结 3 796
既然无缘
既然无缘 2021-01-13 10:06

This is about memory alignment. In code below, I expected that the offset of b inside the structure to be 8 (32-bit machine). See here. There by, making b alway

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-13 10:45

    According to the System V ABI for i386, page 28, double only gets 4 bytes alignment, but compilers are recommended to provide an option for 8 bytes as well. It appears this is what is implemented by GCC on Linux, the option being called -malign-double.

    Another alternative is to use -m64 to get x86-64 object code, which is already the default on some systems including Mac OS X.

提交回复
热议问题