9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Skip Tavakkolian <9nut@9netics.com>
To: 9fans@cse.psu.edu
Subject: Re: [9fans] 8c padding problem
Date: Fri, 21 Dec 2007 18:48:58 -0500	[thread overview]
Message-ID: <68f8eb08905533341341b17b21c8dcc7@9netics.com> (raw)
In-Reply-To: <1ccc8ef58858daba6badd7543df078f4@quanstro.net>

i am guessing that the requirement of being able to demote a type to
one of its anonymouse constituents -- as in Node to Lock in Ken's example --
would require a uniform layout that makes it easy to calculate the offset.

> 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


  parent reply	other threads:[~2007-12-21 23:48 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-21 23:10 erik quanstrom
2007-12-21 23:24 ` Martin Neubauer
2007-12-22  0:00   ` erik quanstrom
2007-12-21 23:48 ` Skip Tavakkolian [this message]
2007-12-21 23:52   ` erik quanstrom
2007-12-21 23:59     ` Skip Tavakkolian
2007-12-22  0:20       ` erik quanstrom
2007-12-22  4:25         ` Bruce Ellis
2007-12-22  4:34           ` erik quanstrom
2007-12-22  4:41             ` Bruce Ellis
2007-12-22 11:09   ` C H Forsyth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=68f8eb08905533341341b17b21c8dcc7@9netics.com \
    --to=9nut@9netics.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).