Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site orca.UUCP Path: utzoo!linus!decvax!tektronix!orca!graham From: graham@orca.UUCP (Graham Bromley) Newsgroups: net.lang.c Subject: re: the one and only objection to C Message-ID: <1265@orca.UUCP> Date: Sat, 22-Dec-84 23:11:50 EST Article-I.D.: orca.1265 Posted: Sat Dec 22 23:11:50 1984 Date-Received: Sun, 23-Dec-84 08:42:38 EST Distribution: net Organization: Tektronix, Wilsonville OR Lines: 29 > I love C. I think it's by far the best compiler based language > that has ever been produced. I only have minor complaint: > why in the world does most C compilers insist on padding structures? > I am currently working on a network driver that needs to handle a data > packet that has a precise structure to it. It's easy to describe the > structure in C, but if the compiler puts in padding between fields, > I can't simply read in a packet on top of a structure. I must > instead "jump" over the padding bytes both going and comming. I agree with your appreciation of C. No ka oi. About your structure problem, there's a reason for it. For example, floats have to be 32 bit word aligned on a VAX for use by float instructions. Also I think a PDP11 requires operands of a mov (as opposed to movb) instruction to be 16 bit word aligned, i.e. an int would have to be 16 bit word aligned. If the compiler didn't do this, before you could use such a structure element you would have to: 1. Copy it as a byte string (using casts) into a variable of the correct type. 2. Do the operation on that variable. 3. Byte copy it back into the structure. i.e. you could use the structure to store data but couldn't do anything with it. However you will have to do this if you really want to be sure you structure is 'packed'. It should be an easy matter to load and unload your structure, by copying each element as a byte string using sizeof to get the appropriate number of bytes. gbgb aka the longjmp artist