Gordon McNutt writes:
> I hope it's something that simple. But the following example makes me
> worry that it is not, as this example does not use structs:
>
> u8 buf[4];
> u16 *a;
> a = &buf[1];
> *a = 4;
IMHO, this is the wrong thing to do regardless of whether it does what
you want or not. If you have a conversion from one data size to
another, convert it by hand. That way it will always be right no
matter what architecture you're on, and if your compiler is worth
ANYTHING, it will optimize to the most efficient code anyway. In the
above instance, I'd say that you would want to do one of the
following:
buf[1] = a & 0xff;
buf[2] = a>>8;
or:
buf[1] = a>>8;
buf[2] = a & 0xff;
If you had:
u32 a;
you'd do this:
buf[0] = a & 0xff;
buf[1] = a>>8;
buf[2] = a>>16;
buf[3] = a>>24;
If you're trying to port existing code, FIX IT, and send it back to
the author. Yes, I have strong opinions about this. I lived through
the "all the world's a VAX" days, and have no wish to be reminded of
it.
-- -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 Thu Sep 14 19:12:00 2000
This archive was generated by hypermail 2.1.8 : Tue May 04 2004 - 09:43:42 EDT