I have this test program: struct P { char a; int b; } __attribute__ ((__packed__));
int f (char & i) { return ++ i; } int f (int & i) { return ++ i; } int f (char * i) { return ++ * i; } int f (int * i) { return ++ * i; } int main () { P x; x.a = 1; x.b = 1; int i = f (x.a) + f (x.b) + f (& x.a) + f (& x.b); return 0; } It compiles with gcc3.3 (gcc version 3.3.6 20050223 (prerelease) [FreeBSD]) but not with gcc.3.4 (gcc version 3.4.4 20050211 (prerelease) [FreeBSD]). GCC reports: test.cpp: In function `int main()': test.cpp:13: error: cannot bind packed field `x.P::a' to `char&' test.cpp:13: error: cannot bind packed field `x.P::b' to `int&' Probably, this is not a bug but a feature, but what can I do to my program, which needs a lot of packed structures and runs fine with gcc3.3? Perhaps I have to cast away the packed attribute somehow ?? I understand, that my code may not work on cpus needing some specific alignment, but where is the problem with char? And if this is a cpu issue, why do the pointers work, but _not_ the references? -- Summary: attribute((packed)) and call by reference Product: gcc Version: 3.4.4 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: nkoch at demig dot de CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i386-portbld-freebsd4.10 GCC host triplet: i386-portbld-freebsd4.10 GCC target triplet: i386-portbld-freebsd4.10 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20316