D
Dave Thompson
On 17 Sep 2006 16:30:39 -0700, "Snis Pilbor" <[email protected]>
wrote:
Because back around 1970 when C was designed, people didn't much
distinguish between "layout of several concrete things in more-or-less
adjacent memory" (like COBOL) and "abstract collection of several
things like a mathematical tuple" and by the time people did start
doing so lots of C implementations and particularly lots of C code
assumed the former and it was judged too late to change.
Languages created more recently, like Ada, or which added struct types
more recently, like Fortran, go (by default) with the latter.
Effectively so do languages that don't have any concrete memory access
at all, like java and perl. I don't remember which way Pascal went;
OT1H Wirth usually likes abstraction, OTOH he likes simplicity and
always doing the same thing the same way -- and he does have variant =
overlaid record parts which can make concrete memory visible, though
not officially or portably.
FWIW C++ compromises(?) by allowing reordering _only_ across access
specifiers in the class (or struct) definition, of which there are
never any in C or in the "not-quite-exactly-C-like" subset of C++.
I don't know of any implementation that has taken advantage of this.
Actually even a C compiler could reorder -- or split apart -- struct
elements under the as-if rule if it can look at all or enough of the
code to make sure none of it depends on the Standard order. This is
usually called InterProcedure Optimization or Whole-Program Analysis
or Optimization. There are periodically reports that certain compilers
do so for (at least?) certain important benchmark codes.
- David.Thompson1 at worldnet.att.net
wrote:
Hmm, this is all very surprising to me: why on earth should the
structure layout depend on the order of the elements in the source? Is
there any reason to do this? Why don't compilers automatically
minimize the size of the structure, that seems like a no-brainer to me?
Because back around 1970 when C was designed, people didn't much
distinguish between "layout of several concrete things in more-or-less
adjacent memory" (like COBOL) and "abstract collection of several
things like a mathematical tuple" and by the time people did start
doing so lots of C implementations and particularly lots of C code
assumed the former and it was judged too late to change.
Languages created more recently, like Ada, or which added struct types
more recently, like Fortran, go (by default) with the latter.
Effectively so do languages that don't have any concrete memory access
at all, like java and perl. I don't remember which way Pascal went;
OT1H Wirth usually likes abstraction, OTOH he likes simplicity and
always doing the same thing the same way -- and he does have variant =
overlaid record parts which can make concrete memory visible, though
not officially or portably.
FWIW C++ compromises(?) by allowing reordering _only_ across access
specifiers in the class (or struct) definition, of which there are
never any in C or in the "not-quite-exactly-C-like" subset of C++.
I don't know of any implementation that has taken advantage of this.
Actually even a C compiler could reorder -- or split apart -- struct
elements under the as-if rule if it can look at all or enough of the
code to make sure none of it depends on the Standard order. This is
usually called InterProcedure Optimization or Whole-Program Analysis
or Optimization. There are periodically reports that certain compilers
do so for (at least?) certain important benchmark codes.
- David.Thompson1 at worldnet.att.net