the one and only objection to C

Graham Bromley graham at orca.UUCP
Sun Dec 23 14:11:50 AEST 1984


> 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



More information about the Comp.lang.c mailing list