paul@uunet.uu.net (Paul Hudson) (12/15/88)
You've just tripped up on one of the oldest no-no's in the C world. Trying to use structs saved in a file on a variety of machines is almost bound not to work! With care (and alignment to large boundaries and ignoring problems of bytes order and ....) it can be done some of the time. I think the best way out is to write a routine to to the I/O on your file, treating it as a byte stream, and fill in or read out of the struct aligned how the host machine wants it. Now that should port .... ;-)! Paul Hudson Snail mail: Monotype ADG Email: ...!ukc!acorn!moncam!paul Science Park, paul@moncam.co.uk Milton Road, Cambridge, CB4 4FQ
marks@sun.com (Mark Stein) (12/23/88)
> I think the best way out is to write a routine to do the I/O on your file, > treating it as a byte stream, and fill in or read out of the struct > aligned how the host machine wants it. Now that should port .... ;-)! Hmmm. This sounds suspiciously like XDR. Designed for precisely this purpose. Portable, too. Hint1: Look at xdrstdio_create(). This attaches an XDR data stream to a stdio file pointer. Hint2: rpcgen can be used to generate XDR routines for your data types independent of whether they will be used in RPC requests. --Mark Stein <marks@sun.com> Sun Microsystems, Distributed System Software