Re: C structure padding

Tom Lord <lord+@andrew.cmu.edu>
Sun, 27 Jun 1993 19:40:25 GMT

          From comp.compilers

Related articles
Permuting fields of records garavel@imag.fr (1993-06-04)
C structure padding drw@zermelo.mit.edu (1993-06-26)
Re: C structure padding pat@tesuji.qc.ca (1993-06-27)
Re: C structure padding lord+@andrew.cmu.edu (Tom Lord) (1993-06-27)
Re: C structure padding jqb@netcom.com (1993-06-27)
Re: C structure padding drw@phragmen.mit.edu (1993-06-28)
Re: C structure padding jqb@netcom.com (1993-06-28)
Re: C structure padding msb@sq.sq.com (1993-06-29)
| List of all articles for this month |
Newsgroups: comp.compilers
From: Tom Lord <lord+@andrew.cmu.edu>
Keywords: C
Organization: School of Computer Science, Carnegie Mellon, Pittsburgh, PA
References: 93-06-012 93-06-069
Date: Sun, 27 Jun 1993 19:40:25 GMT

        I have been wondering [....] Given


                struct bigger { struct tag a; char b; };


        can b be placed in the padding for a, so that sizeof(struct bigger)
        is the same as sizeof(struct tag)?


No. Consider that `sizeof(struct a)' must give the total size,
including padding, if address math is to work correctly.


`bzero( &some_bigger.a, sizeof (struct a) )' should effect only the field
`a' and its possible aliases. The field `b' is not a possible alias since
it is a different field in the same structure.




There is probably a lot of code which assumes this won't happen,
but I can't find anything in the Standard which prohibits it.


If the standard gave a formal (mathematical) model of how the store was
used we could derive this. It could never just enumerate all the
interesting cases that such a model would speak to. So, I think we're
stuck deriving things from informal arguments.
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.