On 20/01/14 13:01, Dan Carpenter wrote: > It would be easy enough to make the compiler complain about any union > which would normally have size which is not a multiple of 4. > > Warning: union will be padded with 2 bytes unless __attribute__((packed)). > > Otherwise you will be fighting this for ever. A good idea, but the problem is that most of the time it just doesn't matter since all users of the data structure do so with the same ABI. We already expect the compiler to take some liberties with padding and alignment since the C standard permits it, so it's only when the exact layout really matters (data structures dealing with hardware, stored to disk, or passed over networks) that it ever becomes a problem. > Are you sure it's padding the unions, and not just treating the unions > as structs? Yes > What is the size of this union? > > union a { > int x; > short y; > }; 4 Thanks James _______________________________________________ devel mailing list devel@xxxxxxxxxxxxxxxxxxxxxx http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel