Gordon McNutt writes:
> I think I have a solution that will work for me:
>
> struct u16_t { u16 a ; } __attribute__ ((packed));
> ...
> u8 buf[4];
> struct u16_t *a ;
> a = (struct u16_t*)&buf[j];
> a->a = 4;
I would do this instead:
buf[j] = (4) & 0xff;
buf[j+1] = (4) >> 8;
It will work regardless of alignment or endianness. And it generates
good code because it all gets peephole-optimized away into the right
thing for the processor in question.
-- -russ nelson <sig.a.t.russnelson.com> http://russnelson.com | Crynwr sells support for free software | PGPok | Damn the firewalls! 521 Pleasant Valley Rd. | +1 315 268 1925 voice | Full connectivity ahead! Potsdam, NY 13676-3213 | +1 315 268 9201 FAX |Received on Fri Sep 15 12:10:36 2000
This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:43:42 EDT