In the code below, the g++ is being overly picky about taking a reference to a packed char. Chars can have any alignment so the error is incorrect. note that the same code using pointers doesn't produce a similar error: =====
struct s1 { char c1; } __attribute__((packed)); char& f(struct s1 *s) { return s->c1; } char * g(struct s1 *s) { return &s->c1; } -- Summary: g++ gives error on reference to packed structure elements Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: raj dot khem at gmail dot com CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i386-redhat-linux GCC host triplet: i386-redhat-linux GCC target triplet: i386-redhat-linux http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21166