Path: utzoo!utgpu!watserv1!watmath!att!linac!uwm.edu!rpi!zaphod.mps.ohio-state.edu!van-bc!ubc-cs!alberta!mts.ucs.UAlberta.CA!Al_Dunbar From: userAKDU@mts.ucs.UAlberta.CA (Al Dunbar) Newsgroups: comp.lang.c Subject: Re: Binary data file compatibility across machines Message-ID: <1967@mts.ucs.UAlberta.CA> Date: 29 Nov 90 02:39:21 GMT References: <2172@tuvie> Organization: MTS Univ of Alberta Lines: 43 In article <2172@tuvie>, hp@vmars.tuwien.ac.at (Peter Holzer) writes: >stiber@cs.ucla.edu (Michael D Stiber) writes: > > >>On different machines, the implementation of C data types is different. <<>> > >For integer data I choose the format that is used on the machines >I am working on most of the time. Each binary data file then >gets a header describing the data format. Something like > > 2 Bytes: 'P' 'B' (portable binary) > 1 Byte: 0 = 2compl., 1 = 1compl., > 2 = sign/mag, > 1 Byte: 0 = little, 1 = big. > ?? > Pardon my curiosity, but, if you write such a file on a particular type of machine, then read it back on another, won't your code have to do some decoding of this header information? Say, for example, you write from an ASCII machine and read from an EBCDIC one. The "PB" will map to some other combination of characters. Will your program determine from whatever they happen to be that the source machine is ASCII? I always forget whether "endianness" refers to the ordering of bytes in words or bits in bytes - if the latter, your program will also have to do some juggling to properly decode the third and fourth bytes. What about machine architectures you don't know about yet? What about 12 and 60 bit machines (PDP8, Cyber)? If transportability is important, use ASCII (pardon, character), and let some o/s utility do the conversion. If efficiency is paramount, use binary and include a disclaimer about moving the file to another machine (you can't, after all, move the executable that way, can you?). If both are crucial, provide a separate conversion program. -------------------+------------------------------------------- Al Dunbar | Edmonton, Alberta | "this mind left intentionally blank" CANADA | - Manuel Writer -------------------+------------------------------------------- #! r