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: Thu, 27 Jul 2006 02:38:13 -0400 (EDT)
- From: Joe Larabell <fred62@???>
- 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>
> Yeah, but it's a *lot* uglier than that. Remember the header! What > you really need is something like: > > union { > struct { > char pad[6]; > char input[10]; > } namadata; > struct { > union { > struct { > char pad[6]; > char header[2]; > } prefix; > double align; > } > double payload; > } yakidata; > } do_you_really_expect_to_pull_this_off_interrobang; Funny... I was going to write something like that but I thought better of it. I was assuming he'd rather copy the interesting chars from the 17-byte struct into the union manually than tackle the data structure necessary to grab the payload from the original string on the fly. > and even then there's no guarantee you'll get a packed structure, or > even that sizeof(char) == 1. Hmmm... my Stroustrup is is pretty old but it does say (sec. 5.3.2) that: "... a byte is undefined by the language except in terms of the value of sizeof: sizeof(char) is 1." Of course, if that's no longer the case, you're always free to use: sizeof( double ) / sizeof( char ) assuming it divides evenly (oh... the pain ;-)... I've seen much worse. A huge program saving data in a non-standard binary format, written before 32-bit machines even existed, later ported by some crazed lunatic to run on a 32-bit machine. Offsets computed by taking a pointer to a representative instance of a number (usually zero) and doing a combination of casts, shifts, and subtractions. I should have saved some examples, as they would make excellent exam material for a course in C ;-). > The former looks like an exceptionally nasty and pointless form of > data torture. Yeah... if they're going to the trouble of emitting an apparently ASCII header, would that not suggest that the whole message is in ASCII? Maybe it would be possible to get a hex dump of the actual bytes returned from this meter -- or to get the model number so someone can try to google up a programmer's manual. --- Joseph L (Joe) Larabell Never fight with a dragon http://larabell.org for thou art crunchy and goest well with cheese.
- Follow-Ups:
- 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
Home | Main Index | Thread Index
- Prev by Date: [tlug] [OT] Lunch Place around Ginza Was: TLUG Technical Meeting 2006-07-29
- Next by Date: Re: [tlug] I'm a glutton for punishment - Palm Pilot and Ubuntu Dapper LTS connectivity [SOLVED]
- Previous by thread: Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- Next by thread: Re: [tlug] Portability of Misaligned Data Access . . . . . . .
- Index(es):
Home Page Mailing List Linux and Japan TLUG Members Links