Path: utzoo!attcan!uunet!zephyr.ens.tek.com!uw-beaver!mit-eddie!bloom-beacon!eru!hagbard!sunic!ericom!eos.ericsson.se!etxtomp From: etxtomp@eos.ericsson.se (Tommy Petersson) Newsgroups: comp.sys.amiga Subject: Re: C standard across machines (question). Message-ID: <1990Oct30.115621.6461@ericsson.se> Date: 30 Oct 90 11:56:21 GMT References: <43072@eerie.acsu.Buffalo.EDU> <15828@netcom.UUCP> Sender: news@ericsson.se Reply-To: etxtomp@eos.ericsson.se Organization: Ericsson Telecom AB Lines: 33 > In a previous article, v069qqqc@ubvmsd.cc.buffalo.edu writes: >> >>I am writing a general purpose database in C. I'm developing it for >>the company I work for so I'm doing it with the ibm XT's they have in mind. >>However, I would like to eventually Amiga-tize it and release it as >>(probably) shareware. I would therefore prefer to make the program (as >>well as the database format) as portable as possible. >> >>The problem is, (correct me if I'm wrong) Intel machines are "little >>endian" whereas Motorolas are "big endian". I assume C adopts one of >>these standards to maintain protability of files between machines. >>My question is, which is the C standard, and how do I ensure that a database >>created on the ibm version will not be garbage on the Amiga version. >>(To add to the confusion, I'm doing the development on a sun... I have >>no idea what the sparc standard is!) For portability of data files, NEVER use int, long... in your program. Have a global header file that's included in all your programs define portable types like BIT16, BIT32 a.s.o. The byte-swap issue could be solved by something like this: Have a 16-bit word in the beginning of a data file contain number 1. If you read this data file on another machine and the word contains 256, the bytes are swapped. You could have your read/write routines do different things depending on this initial test(s) (have a table where you install pointers to function A or B...). However, I don't think byte-swapping is the only problem. Some machines have MSB and LSB different, so this number one can probably become either 1, 128, 256 or 32768... ASCII strings will not get swapped, but integers do, so the read routines will have to know what they are reading. Tommy Petersson