bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: alignof failure


From: Simon Josefsson
Subject: Re: alignof failure
Date: Thu, 14 May 2009 10:02:45 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.93 (gnu/linux)

Bruno Haible <address@hidden> writes:

> Simon Josefsson wrote:
>> The alignof module seems to have problems:
>> 
>> address@hidden:~/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

[Prev in Thread] Current Thread [Next in Thread]