memory alignment __attribute__( ( aligned ( 8 ) ) )

前端 未结 3 1445
死守一世寂寞
死守一世寂寞 2020-12-30 06:21

I got a program in a book

#include 
int main( )
{
    struct data
    {
        int a    __attribute__( ( aligned ( 8 ) ) ) ;
        char ch          


        
3条回答
  •  梦毁少年i
    2020-12-30 07:02

    aligned(8) just means that the address of &e.a will be aligned by 8. And it is (2280712). sizeof(int) is presumably 4, which is why your char ends up at 2280716 (it has an alignment requirement of 1, so there's no reason for it to be pushed to 2280720). Just add sizeof(int) to your debug output to verify it.

    You will need to change your build target settings if you want to use 64-bit ints.

提交回复
热议问题