Edit. Yes this looks to be the case for those of us using C99. Paul Eggert put in a patch for gnulib to cover this [1].
typedef union {
char *__p;
double __d;
long double __ld;
long int __i;
} max_align_t;One thing I did learn looking through this patch was the difference NULL has in C++ and C. This is certainly not something I had ever considered.
1. https://lists.gnu.org/archive/html/bug-gnulib/2014-12/msg001...
You want 8 byte alignment. For one, you could have doubles. (Though I just googled this and apparently gcc will 4 byte align those by default on x86) Another possibility is you could have a data structure that relies on "lock cmpxchg8b".
While there are some cases where this is an issue (writes that cross 4KB page boundaries), this generally isn't true for any x86/x64 processor made in the last decade. There may be legitimate portability reasons for avoiding unaligned access, but performance on x86 is probably not a good reason.
http://www.intel.com/content/dam/www/public/us/en/documents/...
8.1.1 Guaranteed Atomic Operations
The P6 family processors (and newer processors since)
guarantee that the following additional memory operation
will always be carried out atomically:
• Unaligned 16-, 32-, and 64-bit accesses to cached memory that fit within a cache line
The first P6 was Pentium Pro, which came out in 1995. It does go on to say that although modern processors will guarantee atomic operations that cross cache lines, it's a bad practice that can badly hurt performance.