The importance of alignment on a VAX

Norman Diamond ndiamond at watdaisy.UUCP
Wed Mar 20 11:36:02 AEST 1985


> 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 at waterloo.csnet
ARPA:  ndiamond%watdaisy%waterloo.csnet at csnet-relay.arpa

"Opinions are those of the keyboard, and do not reflect on me or higher-ups."



More information about the Comp.lang.c mailing list