Mailing List Archive
tlug.jp Mailing List tlug archive tlug Mailing List Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- Date: Fri, 28 Jul 2006 11:48:21 +0100
- From: "Ian Wells" <ijw@example.com>
- Subject: Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- References: <20060726125907.GH5111@example.com> <87ejw8corz.fsf@example.com> <20060726164125.4959ce4e.jep200404@example.com> <Pine.BSF.4.58.0607261946521.68592@example.com> <87r707bv1o.fsf@example.com> <Pine.BSF.4.58.0607270219370.17463@example.com> <87ac6vbd3l.fsf@example.com>
In my experience at getting random boxes with badly designed protocols/file formats talking to each other, I've concluded: 1. never use byte equivalency between types, be it union or memcpy 2. the endianness will always be wrong. On point (2), let it be noted that you *never*, *ever* have to discover the endianness of your host: uint16_t read_le_u16(char *x) { return (uint16_t)x[0]+(((uint16_t)x[1]) <<8); } In the nature of these things, this looks obviously inefficient and slow, and therefore it's almost guaranteed not to be the thing that takes up the majority of the time (rule #3). Doing the same thing, portably, for a double in IEE754 format is left as an exercise to the bored reader. Who, it is to be hoped, doesn't have to port to VAXen, where the FP formats have a completely different range and accuracy. Believe me, I know. -- Ian.
- Follow-Ups:
- [tlug] Byte Endian Portability and Efficiency . . . . . . . . . . (was Re: Portability of Misaligned Data Access)
- From: Jim
- [tlug] Floating Point Formats. . . . . . . . . . (was Re: Portability of Misaligned Data Access)
- From: Jim
- Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- From: Josh Glover
- References:
- [tlug] issues with format of double (or IEEE754)
- From: Michal Hajek
- Re: [tlug] issues with format of double (or IEEE754)
- From: Stephen J. Turnbull
- [tlug] Portability of Misaligned Data Access . . . . . . . (was Re: issues with format of double (or IEEE754))
- From: Jim
- Re: [tlug] Portability of Misaligned Data Access . . . . . . . (was Re: issues with format of double (or IEEE754))
- From: Joe Larabell
- Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- From: Stephen J. Turnbull
- Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- From: Joe Larabell
- Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- From: Stephen J. Turnbull
Home | Main Index | Thread Index
- Prev by Date: Re: [tlug] Internal floating point formats used by 80387, IEEE 754 and C . . . . .
- Next by Date: [tlug] Xen and VT
- Previous by thread: Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- Next by thread: [tlug] Byte Endian Portability and Efficiency . . . . . . . . . . (was Re: Portability of Misaligned Data Access)
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links