by CountHackulus · 15y ago · 0 comments
#define ALIGN(type, name, align) __ALIGN_MASK(type, name, (align - 1))
#define __ALIGN_MASK(type, name, mask) char __##name##_buffer[sizeof(type) + mask];\
int * name = (type *)((size_t)(__##name##_buffer + mask) & ~mask);
Then you can just use it in the code like so: ALIGN(int, y, 16);
And you've just declared a pointer to a 16-byte aligned int on the stack. Very useful.You also violated the C standard in a less severe way. According to the standard, any identifier name starting with a double underscore (or underscore followed by upper-case letter) is reserved by the implementation for any use. These reserved names are frequently used in system header files, and encroaching on that namespace can easily lead to weird errors if the code is ever compiled on some other system.
As for the double underscore being reserved for implementation use, this was in fact part of the compiler (well, runtime in this case) implementation, again a side-effect of copy and paste.