【发布时间】:2012-01-24 09:43:29
【问题描述】:
我需要为 4 字节对齐的 2 字节变量声明类型别名。
在 GCC、XL C/C++ (AIX)、aCC (HP-UX) 中我可以使用以下代码:
typedef uint16_t AlignedType __attribute__ ((aligned (4)));
在 Windows 中我可以使用:
typedef __declspec(align(4)) unsigned __int16 AlignedType;
如何在 SunStudio C++ 11 中声明相同的类型?
“pragma align”不适合,因为它仅适用于全局或静态变量,并且需要变量名。
【问题讨论】:
-
相关,您也可以使用
__alignof__来确定SunCC 编译器的对齐方式。它是 GCC 的__alignof__之类的扩展。它在 Solaris 9 上的 SunCC 5.8 测试良好。感谢OpenCSW 提供对他们的compile farm 的访问以测试旧的 x86 和 Sparc 机器。
标签: c++ c memory-alignment sunstudio