Xref: utzoo comp.arch:13933 comp.lang.c:25940 Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!van-bc!ubc-cs!alberta!calgary!ctycal!ingoldsb From: ingoldsb@ctycal.UUCP (Terry Ingoldsby) Newsgroups: comp.arch,comp.lang.c Subject: Re: RISC Machine Data Structure Word Alignment Problems? Summary: eXternal Data Format Keywords: risc sun Message-ID: <333@ctycal.UUCP> Date: 14 Feb 90 16:18:04 GMT References: <111@melpar.UUCP> <1990Jan21.224826.1699@esegue.segue.boston.ma.us> <17906@rpp386.cactus.org> Organization: The City of Calgary, Ab Lines: 36 In article <17906@rpp386.cactus.org>, woody@rpp386.cactus.org (Woodrow Baker) writes: > In article <328@ctycal.UUCP>, ingoldsb@ctycal.UUCP (Terry Ingoldsby) writes: > > In article <1648@skye.ed.ac.uk>, richard@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@calgary.UUCP Land Information Systems or The City of Calgary ...{alberta,ubc-cs,utai}!calgary!ctycal!ingoldsb