64 bit architectures and C/C++

CADSI cadsi at ccad.uiowa.edu
Mon May 6 03:58:09 AEST 1991


>From article <1991May03.120455.158 at buster.stafford.tx.us>, by rli at buster.stafford.tx.us (Buster Irby):
> cadsi at ccad.uiowa.edu (CADSI) writes:
> 
>>Binary isn't in general portable.  However, using proper typedefs in
>>a class one can move binary read/write classes from box to box.  I think
>>the solution the the whole issue of sizeof(whatever) is to simply assume
>>nothing.  Always typedef.  It isn't that difficult, and code I've done this
>>runs on things ranging from DOS machines to CRAY's COS (and UNICOS) without
>>code (barring the typedef header files) changes.
> 
> What kind of typedef would you use to swap the high and low bytes
> in a 16 bit value?  An Intel or BIG_ENDIAN machine stores the
> bytes in reverse order, while a Motorolla or LITTLE_ENDIAN
> machine stores the bytes in normal order (High to low).  There is
> no way to fix this short of reading the file one byte at a time
> and stuffing them into the right place.  The point I was trying
> to make is that reading and writing a data file has absolutely
> nothing to do with data types.  As we have already seen, there
> are a lot of different machine types that support C, and as far
> as I know, all of them are capable of reading binary files,
> independent of data type differences.

The big/little endian problem is handled via swab calls.
AND, how do we know when to do this????  We just store
the needed info in a header record.
This header is read in block fashion and typedef'ed to the structure we need.
from there, thats all we need to continue.
The typedefs have to do with internal structures, NOT simple int, char
and those type things, except for the BYTE type.
Last but not least, you'll inevitably ask how we portably read that header.
Well, we store a 'magic number' info and mess with things till the numbers are
read correctly.  Incidentally, that magic number also gives indications
of code revision level and therefore what will and won't be possible.
C'mon, this is not that difficult to comprehend.  You want portable files???
Make 'em yourself.  'C' gives you all the toys you need to do this.

[other stuff deleted - reference above]

|----------------------------------------------------------------------------|
|Tom Hite					|  The views expressed by me |
|Manager, Product development			|  are mine, not necessarily |
|CADSI (Computer Aided Design Software Inc.	|  the views of CADSI.       |
|----------------------------------------------------------------------------|



More information about the Comp.lang.c mailing list