attribute((packed)) and call by reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux