RISC Machine Data Structure Word Alignment Problems?
Wm E. Davidsen Jr
davidsen at sixhub.UUCP
Mon Jan 22 13:50:19 AEST 1990
johnl at esegue.segue.boston.ma.us (John R. Levine) writes:
| long read_long(void)
| {
| long v;
|
| /* read in big endian order */
| v = getc(f) << 24; /* should do some error checking */
| v |= getc(f) << 16;
| v |= getc(f) << 8;
| v |= getc(f);
| return v;
| }
|
| This may seem like more work, but in my experience you write a few of these
| things and use them all over the place. Then your code is really portable.
I agree with your thought, although for portable transfer I usually do
LSB first (not because of any preference) just for the loop. Since I
work with 36 and 64 bit machines, I always add a sign extend on the
read.
At one time I was operating a PC (original IBM) with a unique
coprocessor Cray2 on an ethernet link. The C2 calculated data and passed
it in 32 bit RLE format to a BASIC program which used calls to write the
display. Amazing what you can do to get a demo up FAST.
--
bill davidsen - sysop *IX BBS and Public Access UNIX
davidsen at sixhub.uucp ...!uunet!crdgw1!sixhub!davidsen
"Getting old is bad, but it beats the hell out of the alternative" -anon
More information about the Comp.lang.c
mailing list