Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site fortune.UUCP Path: utzoo!linus!decvax!harpo!ihnp4!fortune!crane From: crane@fortune.UUCP (John Crane) Newsgroups: net.lang.c Subject: Re: C structure alignment - (nf) Message-ID: <3131@fortune.UUCP> Date: Mon, 23-Apr-84 12:16:29 EST Article-I.D.: fortune.3131 Posted: Mon Apr 23 12:16:29 1984 Date-Received: Tue, 24-Apr-84 01:06:01 EST References: <158@haddock.UUCP> Organization: Fortune Systems, Redwood City, CA Lines: 51 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. If you recall my question, I am not interested in getting ints; I want chars. 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). All I legally wanted to do was refer to a single member which happened to be a char. 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. Portability schmortability! Does portability ALWAYS have to be an issue? My question related to converting data from ONE SPECIFIC MACHINE to ANOTHER SPECIFIC MACHINE. I did not make this clear in my original question. Now listen. If I programmed for the DPD-10 and all its foibles, or any other machine for that matter, that's not portable either. Maybe there's a difference between portability and machine-independence. I still put aligning nested structures that begin with chars in the area of dirty tricks. Its one of the things I don't like about BASIC. It assumes you don't know what you are doing and does what it "thinks" is going to make life easier for you. One nice thing about assembly language is that you can control your own alignment. John Crane