std::array alignment

前端 未结 4 1552
情歌与酒
情歌与酒 2020-12-11 03:08

Trying out std::tr1::array on a mac i\'m getting 16 byte alignment.

sizeof(int) = 4;  
sizeof( std::tr1::array< int,3 > ) = 16;  
sizeof         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-11 03:59

    std::array is actually not an array, but a struct that contains an array. It's the struct that is padded, not the array. Compilers are allowed to add padding to the end of a struct whenever they want.

提交回复
热议问题