What should alignof do with incomplete types?
Jamie Lokier
jamie.lokier@cern.ch
Tue Mar 7 04:22:00 GMT 2000
Stan Shebs wrote:
> GCC (2.90) results in:
>
> Alignment of a is 4
> Alignment of b is 0
>
> Apple's version of GCC warns about struct b, and reports
> 1 instead of 0, so as avoid possible divides by zero:
Both 0 and 1 would break some of my programs, in the event that I had an
incomplete type kicking around. And my code is not that unusual: I have
an inline memory allocator which rounds address according to the type
being allocated.
The reason it would break is because the alignment would have a
different value in different contexts.
> The change is very simple, but it occurs to me that the current
> behavior might be deliberate, although it's not specified either way
> in the manual. On the other hand, one could make the case that alignof
> on an incomplete type should be an error rather than just a warning,
> since it's hard to imagine how this could be legitimate code, and
> since the compiler is unlikely to be able to guess at a correct value.
>
> In any case, before preparing a patch, I'd like to know whether the
> current behavior is considered to be a problem.
IMO an error is appropriate, just as for sizeof. Does Apple have code
which depends on this being a just warning?
-- Jamie
More information about the Gcc
mailing list