On Wed, 13 Sep 2017, Bernd Edlinger wrote: > On 09/13/17 19:06, Joseph Myers wrote: > > What does this warning do in cases where a type has different alignments > > inside and outside structs? I'm thinking of something like > > > > struct s { long long x; } *p; > > /* ... */ > > (long long *)p > > > > on 32-bit x86 - where long long's preferred alignment is 8 bytes, but in > > structures it's 4 bytes. (Likewise for double in place of long long.) I > > think a warning for a (long long *)p cast might be surprising in that > > case. > > > > Well, yes this does get a warning. But doesn't that cast then violate > the underlying alignment requirement of long long* ?
That's the difference between preferred alignment (__alignof__) and alignment required in all contexts (C11 _Alignof). The above seems valid, just like it's valid to take the address of a long long struct element. That is, the alignment for the target of a pointer to long long is really 4 bytes here, even though the alignment for a standalone long long object is 8 bytes. And there's a case for the warning to look at the required alignment in all contexts, not TYPE_ALIGN. -- Joseph S. Myers jos...@codesourcery.com