Portability across architectures..

T. William Wells bill at proxftl.UUCP
Mon Aug 29 15:44:58 AEST 1988


In article <103 at simsdevl.UUCP> dandc at simsdevl.UUCP (Dan DeClerck) writes:
: I've run across a need to have data files in various forms of UN*X
: be portable to each other. Mostly, this deals with Intel to Motorola and
: vice-versa. I could write data out to files in ASCII, but this is cumbersome,
: slow and may hamper the products' marketability.
:
: The problem lies in writing integers as well as structures to
: files, and allow those files to be transferred between a
: multitude of machines without a data transformation taking
: place.
:
: A fellow programmer suggested an "XDR" standard from SUN, but
: this seems to only work with inter-process communication.  Has
: anyone encountered this problem??

As I understand it, XDR includes a description of the data *as it
is transmitted* as well as a set of conversion routines.  For
example, on the man page for our Sun 3 is:

xdr_array()  translate arrays to/from external representation
xdr_bool()   translate Booleans to/from external representation
xdr_bytes()  translate counted byte strings to/from external representation
xdr_double() translate double precision to/from external representation
xdr_enum()   translate enumerations to/from external representation
xdr_float()  translate floating point to/from external representation
xdr_int()    translate integers to/from external representation
xdr_long()   translate long integers to/from external representation
xdr_opaque() translate fixed-size opaque data to/from external representation
xdr_short()  translate short integers to/from external representation
xdr_string() translate null-terminated strings to/from external representation
xdr_u_int()  translate unsigned integers to/from external representation
xdr_u_long() translate unsigned long integers to/from external representation
xdr_u_short()translate unsigned short integers to/from external representation
xdr_union()  translate discriminated unions to/from external representation

Presumably, what you want to do is to use these routines to
convert your data and then write the data to a file; then use
them to convert the data back when read it.

---
Bill
novavax!proxftl!bill



More information about the Comp.lang.c mailing list