Re: C structure padding

pat@tesuji.qc.ca (Patrick Smith)
Sun, 27 Jun 1993 16:12:04 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: pat@tesuji.qc.ca (Patrick Smith)
Keywords: optimize, C
Organization: Compilers Central
References: 93-06-012 93-06-066
Date: Sun, 27 Jun 1993 16:12:04 GMT

Dale Worley (drw@math.mit.edu) writes:
|For example: Suppose we have a machine with the length and alignment
|requirements:
| integer length 4 alignment 4
| char length 1 alignment 1
|
|If I have a structure:
| struct tag { int a; char b; };
...
|But-- If I just declare a variable with type struct tag, must the full
|8 bytes be allocated to it, or can the compiler give it 5 and pack
|some other variable(s) in the following 3 bytes?


I have been wondering about an almost identical question. 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)?


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.




Our moderator writes:
|[It's pretty clear that all structures have to be treated the same, since
|if p and q are pointers to structures, you can write *p = *q regardless of
|whether they're pointing to simple structures or into an array. -John]


Yes, but the code generated for a structure assignment does not
have to copy the padding.
--
Patrick Smith
pat@tesuji.qc.ca
uunet.ca!frumious!pat
--


Post a followup to this message

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