Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/3/84; site sesame.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!panda!talcott!sesame!rick From: rick@sesame.UUCP (Rick Richardson) Newsgroups: net.lang.c Subject: Re: Un-alignment in structures Message-ID: <165@sesame.UUCP> Date: Mon, 18-Mar-85 13:06:30 EST Article-I.D.: sesame.165 Posted: Mon Mar 18 13:06:30 1985 Date-Received: Tue, 19-Mar-85 06:13:36 EST References: <9239@brl-tgr.ARPA> Organization: Free-Access Unix in Boston Lines: 28 > the reason for the padding, which admittedly does not hold for > some machines, is that many machines, notably the pdp-11, can not > handle words generated at an odd address. The original author (sorry I don't have rn, and lost his name) wanted unaligned structures for what looks like a very legitimate and portable reason. He's trying to package up a block of data which is to be sent over a serial line. Probably some protocol. He would love to give symbolic names to the pieces of data instead of trying to pack the stuff by hand into a character array (using >>8 and &0xff, etc.). His ultimate goal is to issue a "write(fd, &block, sizeof(block));". This feature wouldn't cause any problem with word alignment, if used in this manner. The problem is that even if the padding is eliminated with some language construct, he is still going to have machine dependencies in two areas: an assumption that "short" or "int" is a specific length (probably 16 or 32 bits), and that the byte ordering of such things is the same on his machine as specified by the protocol and also of all machines to which he may port. This is not the case, and the only portable way to do this is by shifting and masking the stuff into a character array. The net is that he is specifically asking for a language feature that will lull him into a sense of portability that isn't really present. -- Rick Richardson, PC Research, Inc. {genrad|ihnp4|ima}!wjh12!talcott!sesame!{rick|pcrat!rick} {cbosgd|harvard}!talcott!sesame!{rick|pcrat!rick} rick%sesame@harvard.ARPA