我需要为2字节变量声明类型别名,并按4字节对齐。
在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提供访问他们的编译农场以测试旧的x86和Sparc机器。 - jww