I use g++ to compile code with packed fields. However, I receive an error when trying to return a reference to a packed field.
Example:
struct __attribute__((packed)) Foo {
int* ptr;
uint16_t foo;
int*& getPtr(){
return ptr;
}
};
yields error:
test.cpp:22:14: error: cannot bind packed field ‘((Foo*)this)->Foo::ptr’ to ‘int*&’
return ptr;
Why can't I return a reference to a packed field?
return (int*&)ptr;
– Incurvate