8 byte alignment on capn_segment, updated comments about this.

As discussed in PR: https://github.com/opensourcerouting/c-capnproto/pull/15#discussion_r107588334
This commit is contained in:
Alex Helfet 2017-03-23 05:11:45 +00:00
parent 57d0ffea33
commit 408505ae31
2 changed files with 14 additions and 8 deletions

View file

@ -19,10 +19,15 @@
#include <limits.h>
#include <errno.h>
/* Visual Studio notes:
* Unless capn_segment is defined with __declspec(align(64)), check_segment_alignment
* Fails to compile in x86 mode, as (sizeof(struct capn_segment)&7) -> (44 & 7) evaluates to 4
* Compiles in x64 mode, as (sizeof(struct capn_segment)&7) -> (80 & 7) evaluates to 0
/*
* 8 byte alignment is required for struct capn_segment.
* This struct check_segment_alignment verifies this at compile time.
*
* Unless capn_segment is defined with 8 byte alignment, check_segment_alignment
* fails to compile in x86 mode (or on another CPU with 32-bit pointers),
* as (sizeof(struct capn_segment)&7) -> (44 & 7) evaluates to 4.
* It compiles in x64 mode (or on another CPU with 64-bit pointers),
* as (sizeof(struct capn_segment)&7) -> (80 & 7) evaluates to 0.
*/
struct check_segment_alignment {
unsigned int foo : (sizeof(struct capn_segment)&7) ? -1 : 1;