You ought to be able to test that with something like:

struct {long long N} a;
char b;
struct {long long N} c;
int d;

d=&c - &a; /* I can't remember if you need to cast c & a as char to
get byte distance */

printf("a is at %d, c is at %d, they are %d apart\n",&a,&c, d);
-y


On Sun, May 4, 2014 at 6:26 AM, Nicholas Clark <n...@ccl4.org> wrote:
> Just for the record:
>
> $ cat sizer.c
> #include <stdio.h>
> int main() {
>     printf("             sizeof(long long) = %2u                  
> __alignof__(long long) = %2u\n", (unsigned) sizeof(long long),  (unsigned) 
> __alignof__(long long));
>     printf(" sizeof(struct {long long N;}) = %2u      __alignof__(struct 
> {long long N;}) = %2u\n", (unsigned) sizeof(struct {long long N;}),  
> (unsigned) __alignof__(struct {long long N;}));
>     return 0;
> }
> $ gcc -Wall -o sizer sizer.c
> $ ./sizer
>              sizeof(long long) =  8                  __alignof__(long long) = 
>  8
>  sizeof(struct {long long N;}) =  8      __alignof__(struct {long long N;}) = 
>  4
>
> Yes, this was a surprise.
>
> I knew that structures can cause padding to be introduced, and arrays can have
> higher alignment constraints than their elements.
>
> But lowering alignment constraints?
>
> Is __alignof__() telling the truth here?
> Or is it giving a truthful less-than-useful answer?
>
> (Because what matters to MoarVM is the alignment of, and therefor padding
> needed for, structure members)
>
> Nicholas Clark

Reply via email to