RE: [GD-General] Some portability questions
Brought to you by:
vexxed72
From: Tom F. <to...@mu...> - 2002-11-08 19:16:40
|
Nothing wrong with answer (1) - it's the way I've done it in the past. Zealots would advocate you use a union rather than a cast, but we've had that particular religious war. I thought the early Alphas were even worse - they didn't have bytes. So string handling all had to be emulated with shifts and masks and nastiness like that. I think your answer is pretty acceptable though - stuff 'em. No mass-market architecture is going to make that mistake again in a hurry. Tom Forsyth - Muckyfoot bloke and Microsoft MVP. This email is the product of your deranged imagination, and does not in any way imply existence of the author. > -----Original Message----- > From: Brian Hook [mailto:bri...@py...] > Sent: 08 November 2002 18:58 > To: gam...@li... > Subject: [GD-General] Some portability questions > > > Okay, these are fun ones. Let's do the easy one first. > > 1.) How do you portably and safely byte swap a floating point value? > > Disregarding the whole "some architectures aren't IEEE and/or > don't have > 32-bit floats" issue, it seems like the right way to do this safely is > to cast the bits to an integer value, swap those, and store out as > integer. To load a floating point value, you perform the inverse, and > pray that you didn't load some invalid thing that will generate an FP > exception on some systems. > > I hadn't really thought about this until I started working on POSH > (Portable Open Source Harness). > > 2.) How do you cleanly handle architectures where, say, all data types > are either 1-byte or 8-bytes. The Cray and early 21064 > Alphas were like > this (actually, I don't think early Alphas even had atomic <8-byte > read/writes). > > Answer: it's a Cray, dude. Shut up. If I can't figure out a clean, > safe way of handling this, I may just punt on those architectures. > > Brian |