Jakub Jelinek <ja...@redhat.com>: > On Mon, Nov 10, 2014 at 12:52:02AM -0800, Martin Uecker wrote: > > Jakub Jelinek <ja...@redhat.com>:
... > > The warning seems very useful to me and can easily be turned off. > > Or one could add -W(no-)warn-struct-hack if really needed. > > > > Another odd case is: > > > > struct h0b { > > int i; > > int j[0]; > > int k; > > }; > > > > struct h0b* h0b = ... > > > > h0b->j[4] = 1; > > -fsanitize=undefined should catch this. sanitize is not a replacment for a compile-time warning. The later are much more useful. > > > You haven't provided struct h definition, > > > > Sorry, this should have been sizeof(struct h3). > > In that case the code you've posted is valid, there should be no warnings or > runtime error messages. I meant malloc(sizeof(h3)) without the additional term. But it is undefined behavior in any case, so I would expect a compiler to give a warning. Martin