A somewhat portable way to define an array of char
aligned on 32 bit boundaries is this:
union {
char array[223];
unsigned long ul;
} u;
u
will be aligned on a 32-bit boundary or possibly a larger power of 2 if type unsigned long
requires it, which is very probable on your system. The array is accessed as u.array
. No pragmas, no C11 specific syntax, no compiler specific extension.
If type uint32_t
is available, you could use it in place of unsigned long
.
This solution is not really portable, but a work around for outdated compilers that do not support the _Alignas
specifier. Your compiler does not seem up to date with the current (or the previous) C Standard.
The only correct solution is to use the _Alignas
specifier. If you give more context such as what system and compiler you use and why you need 32-bit alignment, a better solution could be found for your problem.