Re: Optimizing structure layout

Valentin Bonnard <>
31 Mar 1997 22:20:25 -0500

          From comp.compilers

Related articles
[2 earlier articles]
Re: Optimizing structure layout (1997-03-22)
Re: Optimizing structure layout (Christopher Glaeser) (1997-03-22)
Re: Optimizing structure layout (Michael Meissner) (1997-03-27)
Re: Optimizing structure layout (David L Moore) (1997-03-27)
Re: Optimizing structure layout (1997-03-31)
Re: Optimizing structure layout (John Pieper) (1997-03-31)
Re: Optimizing structure layout (Valentin Bonnard) (1997-03-31)
| List of all articles for this month |

From: Valentin Bonnard <>
Newsgroups: comp.compilers
Date: 31 Mar 1997 22:20:25 -0500
Organization: Internet Way
References: 97-03-130 97-03-157
Keywords: storage, optimize, C++ writes:
  > While it is quite common that compilers optimize the code they
  > produce, I haven't heard of a commonly used system that really
  > optimizes the layout of the data structures that are generated. Are
  > there such systems?

Michael Meissner wrote:
> For many languages, it is impossible. C for one requires that
> structure members be laid out in the order the programmer wrote
> them. I believe C++ allows classes to be optimized, but again, not
> structures.

No, class and struct aren't different at all.

The only case where th order is unspecified is like this one:

struct T { // or class
          int i;
          int j;

The position of i compared to j is unspecified; this
isn't sufficient to do usefull optimisations.

IMO this is bad; it prevent optimisations such as:

struct T {
          char c1;
          int i;
          char c2;

sizeof (T) == 12


struct T2 {
          int i;
          char c1;
          char c2;

sizeof (T2) == 8

Layout of T1
pos size type name
0 1 char c1
1 3 padding
4 4 int i
8 1 char c2
9 3 padding

Layout of T2
pos size type name
0 4 int i
4 1 char c1
5 1 char c2
6 3 padding

Valentin Bonnard (Informations sur le C++ en Francais)

Post a followup to this message

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