[Bug c/51628] __attribute__((packed)) is unsafe in some cases

ebotcazou at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Apr 3 07:30:00 GMT 2013


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51628

--- Comment #19 from Eric Botcazou <ebotcazou at gcc dot gnu.org> 2013-04-03 07:29:51 UTC ---
> Not sure if I can agree with (or understand) this comment. If we use my example
> of the address of an int in a packed structure being assigned to an int* then
> one could argue that there is a kind of implicit cast happening. The pointer is
> to an integer WITH the default alignment which would be 4 on the ARM system I
> work with. The int in the struct has an alignment of 1 and so the two types
> need to be regarded as being incompatible and there should be an unconditional
> warning or at least -Wcast-align should enable such a warning.

Yes, a warning should probably be implemented in the C family of compilers, but
this is a very old issue and nobody is really interested.  Note that taking the
address of the field is OK, the problem is dereferencing it.



More information about the Gcc-bugs mailing list