Re: Permuting fields of records

drw@runge.mit.edu (Dale R. Worley)
Sun, 6 Jun 1993 18:26:02 GMT

          From comp.compilers

Related articles
Permuting fields of records garavel@imag.fr (1993-06-04)
Re: Permuting fields of records drw@runge.mit.edu (1993-06-06)
Re: Permuting fields of records nickh@CS.CMU.EDU (1993-06-08)
Re: Permuting fields of records henry@zoo.toronto.edu (1993-06-09)
C structure padding drw@zermelo.mit.edu (1993-06-26)
| List of all articles for this month |
Newsgroups: comp.compilers
From: drw@runge.mit.edu (Dale R. Worley)
Keywords: C
Organization: MIT Dept. of Tetrapilotomy, Cambridge, MA, USA
References: 93-06-012
Date: Sun, 6 Jun 1993 18:26:02 GMT

garavel@imag.fr (Hubert Garavel) writes:
      We are currently considering the problem of packing "record" types by
      modifying the order of the record fields. For instance, the following C
      structure


My memory of the solution is: Assuming that the alignment restrictions
(e.g., 1 byte, 2 bytes, 4 bytes) are all mutualy divisible, and assuming
that the size of each object is divisible by its alignment restriction,
then you can get optimal packing by just allocating fields in order of
decreasing alignment restriction.


However, ANSI C requires that the fields of a struct be allocated in the
order they are declared. In addition, it may be that structs need not be
padded to a multiple of their alignment restriction. (Can "struct { short
a; char b; }" be allocated only 3 bytes?)


Dale


Dale Worley Dept. of Math., MIT drw@math.mit.edu
--


Post a followup to this message

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