C structure size
3 messages in this thread
Jerry,
A structure is free to be an odd size and still allow arrays to have a
padding byte so that alignment is maintained. I don't see any problems
with this method.
— Mike Roth / Lattice
Mike –
I tried the -w option in the compile as you suggested, and it made no
difference. The structure with the three char fields gives a sizeof() of 3,
and the structure with the 4 4-bit fields gives a sizeof() of 4. I was
hoping the second structure would be 2 bytes (16 bits) as described since I
wanted to traverse a word (16-bit) array as an array of these structures. I
ended up having to use masks and shifts to do the job (though that's
probably what the compiler would have generated anyway).
I'm not sure if it's even worth looking into, since there _are_
workarounds, but it's certainly not what I expected. Anyway, I've made a
note in my manual in case I forget 8^). If you do find out anything about
this, I would be interested in knowing. Thanks …
Harry
Harry,
I'll check on the way bitfields are being handled. The character fields
should give you a size of 3 since they have no alignment constraints.
— Mike Roth / Lattice