This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/47273] References to unaligned packed structure members not allowed


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&â


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]