Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 exptools 1/6/84; site ihnet.UUCP Path: utzoo!linus!philabs!cmcl2!floyd!harpo!ihnp4!ihnet!tjr From: tjr@ihnet.UUCP (Tom Roberts) Newsgroups: net.lang.c Subject: C structure alignment Message-ID: <122@ihnet.UUCP> Date: Wed, 11-Apr-84 10:20:24 EST Article-I.D.: ihnet.122 Posted: Wed Apr 11 10:20:24 1984 Date-Received: Fri, 13-Apr-84 01:20:22 EST Organization: AT&T Bell Labs, Naperville, IL Lines: 25 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