Path: utzoo!utgpu!water!watmath!clyde!ima!haddock!karl From: karl@haddock.ISC.COM (Karl Heuer) Newsgroups: comp.lang.c Subject: struct alignment (was: While talking about useful additions, ...) Message-ID: <2398@haddock.ISC.COM> Date: 27 Jan 88 02:36:36 GMT References: <253@vsi1.UUCP> <127@ghostwheel.UUCP> <2376@haddock.ISC.COM> <7178@brl-smoke.ARPA> Reply-To: karl@haddock.ima.isc.com (Karl Heuer) Organization: Interactive Systems, Boston Lines: 18 In article <7178@brl-smoke.ARPA> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >In article <2376@haddock.ISC.COM> karl@haddock.ima.isc.com (Karl Heuer) writes: >>Thus, struct{char} and struct{int} may have different alignment constraints. > >I used to think that, too, but a few weeks ago after discussion with >Dennis Ritchie I realized that all struct pointers have to "smell" the >same, which implies that they might as well have the same alignment. The way I see it, you have two choices on a word-addressible machine: either word-align all structures (and use word pointers for struct pointers), or use the minimal required (VAX-like) alignment (and use byte pointers for all structs, even those that are known to be word-aligned.) C vendors on such machines will have to weigh the time-space tradeoff, but there's no reason to penalize the folks who use byte-addressible machines. On a VAX, where all pointers "smell" the same anyway, there should be no problem with struct{char} having char alignment. (Of course, the user can't portably depend on it.) Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint