This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/47273] References to unaligned packed structure members not allowed
- From: "waldemarbancewicz at ruggedcom dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 14 Jan 2011 13:42:06 +0000
- Subject: [Bug c/47273] References to unaligned packed structure members not allowed
- Auto-submitted: auto-generated
- References: <bug-47273-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47273
--- Comment #2 from Waldemar Valdas Bancewicz <waldemarbancewicz at ruggedcom dot com> 2011-01-14 13:42:03 UTC ---
Consider the following program test.c:
#include <stdio.h>
struct s {
char a;
int b;
int* GetValp() { return &b; }
int& GetValr() { return b; }
} __attribute__((packed));
int main() {
struct s s1;
*(s1.GetValp()) = 150;
s1.GetValr() = 5;
printf("%d\n", s1.b);
}
When trying to compile we get the following error message:
waldemarbancewicz@waldemarbancewicz:~/tmp$ g++ -o test test.c
test.c: In member function âint& s::GetValr()â:
test.c:7: error: cannot bind packed field â((s*)this)->s::bâ to âint&â