attribute((packed)) and call by reference
Norbert Koch
NKoch@demig.de
Mon Mar 7 13:44:00 GMT 2005
I have this program:
struct P { char a; int b; } __attribute__ ((__packed__));
int f (int & i) { return ++ i; }
int main ()
{
P x;
x.a = 1; x.b = 1;
int i, b, * p;
/* does work */
b = x.b; i = f (b); x.b = b; // (1)
/* does work for gcc-3.3.6 */
/* does _not_ work for gcc-3.4.4 */
i = f (x.b); // (2)
/* does work for gcc-3.3.6 */
/* does work for gcc-3.4.4 (?) */
p = & x.b; i = f (* p); // (3)
return 0;
}
I understand that (2) and (3) are not portable and therefore
should not be allowed (although (3) is accepted by the compiler).
So does someone have an idea how to simplify
b = x.b; i = f(b); x.b = b;
to something like
i = f (Temp (x.b));
I tried hard using templates and macros but did not find a solution.
Perhaps there is some gcc specific low level interface for accessing
packed members of a struct?
Thanks for any help.
More information about the Gcc-help
mailing list