Bruno Haible <br...@clisp.org> writes:

> Simon Josefsson wrote:
>> The alignof module seems to have problems:
>> 
>> j...@mocca:~/src/gnulib master$ gnulib-tool --test --with-tests alignof
>> ...
>> ../../gltests/test-alignof.c:41: error: negative width in bit-field 
>> ‘verify_error_if_negative_size__’
>
> I reproduce with all versions of gcc since 3.1, on x86, when -malign-double
> is not specified.
>
>   offsetof (struct { char slot1; double slot2; }, slot2)
> is 4 by default, but 8 when -malign-double is specified.
>
> Whereas
>   __alignof__ (double)
> is always 8 on x86; this is even part of the GCC test suite [1].
>
> [2] says: "It turns out that the alignment of a type can differ from the
>   alignment of a field of that type. In particular, on x86 alignof(double)
>   is 8, but a double as a field has alignment 4."
>
> I'm not sure which one we should use in gnulib. Probably the "alignment of a
> field of that type" semantics, because that's what we use alignof for?

Yes.  I suggest adding a comment about this, or rename alignof to
alignof_field to avoid confusion, and fix the self-test.  Maybe there
could be an alignof_type macro too?

/Simon


Reply via email to