Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watdaisy.UUCP Path: utzoo!watmath!watdaisy!ndiamond From: ndiamond@watdaisy.UUCP (Norman Diamond) Newsgroups: net.lang.c Subject: Re: The importance of alignment on a VAX Message-ID: <7095@watdaisy.UUCP> Date: Tue, 19-Mar-85 20:36:02 EST Article-I.D.: watdaisy.7095 Posted: Tue Mar 19 20:36:02 1985 Date-Received: Wed, 20-Mar-85 04:15:09 EST References: <466@lll-crg.ARPA> Distribution: net Organization: U of Waterloo, Ontario Lines: 33 > For those who want to read structures from files using a single read > the best course to follow is write the stuff into the file using the > same structure. The padding for alignment is automatically taken care of. > If the padding cant be tolerated then the most portable course of action > is to read each data item into the structure seperately. This will save you > a lot of headaches when moving your code from one machine to another. So if your data files are supposed to be accessible by programs in any other language, or by programs in the same language compiled by a different compiler -- on the same machine and/or on other machines -- then you should read each data item separately. If you're writing a network interface, don't dare read N bytes of header into a structure. Read each byte separately. Hope your code can respond in time. If you have a bunch of old files and a new compiler, don't just copy your files -- convert them and convert the padding. How can one source program adapt a structure to different padding for the output file than for the input file? By coding in assembly? Yes, padding really has some disadvantages. There should be an OPTION to disable it. -- Norman Diamond UUCP: {decvax|utzoo|ihnp4|allegra}!watmath!watdaisy!ndiamond CSNET: ndiamond%watdaisy@waterloo.csnet ARPA: ndiamond%watdaisy%waterloo.csnet@csnet-relay.arpa "Opinions are those of the keyboard, and do not reflect on me or higher-ups."