RISC Machine Data Structure Word Alignment Problems?

Terry Ingoldsby ingoldsb at ctycal.UUCP
Thu Feb 15 03:18:04 AEST 1990


In article <17906 at rpp386.cactus.org>, woody at rpp386.cactus.org (Woodrow Baker) writes:
> In article <328 at ctycal.UUCP>, ingoldsb at ctycal.UUCP (Terry Ingoldsby) writes:
> > In article <1648 at skye.ed.ac.uk>, richard at aiai.ed.ac.uk (Richard Tobin) writes:
> > This discussion, IMHO, is pointless.  The C compilers work just fine the way
> > are (or at least the ones I am familiar with).  I don't think some of the
> > people discussing this realize the implications of what they propose.
> Wrong.  It depends on what you do.  I happen to do programming dealing
> with industrial controllers.  Specificaly, I maintain a compiler, editor
> downloader, and monitor package used to program Eagle Signal Controls
> EPTAK series industrial controllers.  The code that I work on runs under
> MS-DOS.  I have to do things like reach out over the network, and read
> data structures out of the remote controllers.  These structures for the
> most part, are a mix of byte and word fields.  I then have to parse through
> them, and isolate the parts.  Structures are the obvious way to do this.
> BUT, the @#$% compiler choses to pad byte or char values out to ints.
If you are passing values across a network to dissimilar machines, you
should be using something like the XDR (External Data Representation).  This
 makes for portable (although messy) code.  In your case, I would agree that
your compiler might reasonably be considered to be malfunctioning, since
the Intel processors can access arbitrarily aligned data.  The discussion
originally discussed RISC processors which can NOT access arbitrary
alignments for all data types.  In this case padding is necessary.  To
minimize the amount of padding, it is necessary to reorder the structure
elements.  This is in accordance with K&R which (as I recall) explicitly
states that the elements may be re-ordered.
 
I re-iterate my original claim; it is not the compilers that are causing
the problems (your case excepted).  Rather, it is the fact that different
processors have different access requirements for data types.  Even if you
wrote your programms in RISC assembler (a horrible thought) then you could
not align your variables arbitrarily.  You would be forced to make the
same decisions/tradeoffs that the compilers make.
-- 
  Terry Ingoldsby                ctycal!ingoldsb at calgary.UUCP
  Land Information Systems                 or
  The City of Calgary       ...{alberta,ubc-cs,utai}!calgary!ctycal!ingoldsb



More information about the Comp.lang.c mailing list