指定64位对齐 [英] Specifying 64-bit alignment

查看:516
本文介绍了指定64位对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于像

struct foo {
    int a, b, c;
};

什么是指定它应该始终对齐到64位地址的最佳(最简单,最可靠和便携式)的方式,即使是在32位版本的?我使用C ++ 11与GCC 4.5.2,并希望也支持锵。

What's the best (simplest, most reliable and portable) way to specify that it should always be aligned to a 64-bit address, even on a 32-bit build? I'm using C++11 with GCC 4.5.2, and hoping to also support Clang.

推荐答案

既然你说你正在使用GCC并希望支持铛,GCC的对齐attribute 应该做的伎俩:

Since you say you're using GCC and hoping to support Clang, GCC's aligned attribute should do the trick:

struct foo {
    int a, b, c;
} __attribute__((__aligned__(8))); // aligned to 8-byte (64-bit) boundary

这篇关于指定64位对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆