From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <1ccc8ef58858daba6badd7543df078f4@quanstro.net> From: erik quanstrom Date: Fri, 21 Dec 2007 18:10:10 -0500 To: 9fans@cse.psu.edu MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: [9fans] 8c padding problem Topicbox-Message-UUID: 1ffe9502-ead3-11e9-9d60-3106f5b1d025 i've got a structure that looks like this /* ethernet header */ typedef struct{ uchar d[6]; uchar s[6]; uchar type[2]; }Ehdr; typedef struct{ Ehdr; uchar op[2]; ... }Pkt; the problem is that 8c adds two bytes of padding between the end of pkt->type and pkt->op. since sizeof Ehdr%wordsize != 0 this isn't totally unexpected. suprisingly, adding the appropriate packed pragmas doesn't eliminate the padding. is this a bug? of course, if my original definition had been typedef struct{ uchar d[6]; uchar s[6]; uchar type[2]; uchar op[2]; ... }Pkt; i would have been fine. but doesn't this defeat the point of unnamed structures? also, the fact that there is padding contradicts my mental model of unnamed structures. i thought that all the elements of unnamed structures were laid down as if they were elements of the enclosing structure. my reading /sys/doc/compilers.ps doesn't say much. is there another reference on unnamed structures? - erik