Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!akgua!mcnc!decvax!cca!ima!haddock!johnl From: johnl@haddock.UUCP Newsgroups: net.lang.c Subject: Re: C structure alignment - (nf) Message-ID: <158@haddock.UUCP> Date: Sat, 21-Apr-84 23:38:05 EST Article-I.D.: haddock.158 Posted: Sat Apr 21 23:38:05 1984 Date-Received: Mon, 23-Apr-84 00:58:06 EST Lines: 30 #R:ihnet:-12200:haddock:12400007:000:1335 haddock!johnl Apr 21 13:11:00 1984 ***** haddock:net.lang.c / ihnet!tjr / 1:11 pm Apr 20, 1984 Structure alignment in C varies, depending upon which machine you are on! Many CPU's cannot reference an int at an odd-byte address, so their C-compiler ALWAYS locates a structure on an even-byte address. On some machines (with 4-byte int's), the restriction is to 4-byte addresses. This applies to structures within structures, even when the structures only contain char-arrays. Note that the compilers are permitted to do this, because the only LEGAL things you can do to a structure are to take its address, reference a single member, or assign the entire structure to another structure of the same type (newer C-compilers only). Internal padding can never be significant for these operations (see the recent discussion of == for structures). It is NOT PORTABLE to assume the ordering of members within a structure, nor to assume they are contiguous in memory. Some machines that are not byte-addressable may have some big surprises here (the PDP-10 comes to mind). For all byte-addressable machines with which I am familiar, if you make EVERY member of a structure a multiple of 4 bytes long, data can be passed between machines in the format of the structure, ASSUMING THE BYTE-ORDERING IS THE SAME, OR HAS BEEN CORRECTED. Tom Roberts ihnp4!ihnet!tjr ----------