I need to declare type alias for 2 bytes variable aligned by 4 bytes.
In GCC, XL C/C++ (AIX), aCC (HP-UX) I can use this code:
typedef uint16_t AlignedType __attribute__ ((aligned (4)));
In Windows I can use:
typedef __declspec(align(4)) unsigned __int16 AlignedType;
How can I declare same type in SunStudio C++ 11?
"pragma align" isn't suitable because it works only for global or static variable and It requires variable name.
It might be worth at least trying:
This of course makes accessing a bit more painful, and kills direct assignment so it might break your entire code base. Also, it's purely based on the assumption that including a larger type, which is assumed to have "native alignment" of 32 bits due to being of that size, makes the
unionas a whole align on 32 bits.