Re: Warning: The structure contains misaligned fields
- From: "jamesgiles@xxxxxxx" <jamesgiles@xxxxxxx>
- Date: Mon, 28 Apr 2008 14:58:56 -0700 (PDT)
On Apr 28, 1:39 pm, Craig Powers <eni...@xxxxxxxxxx> wrote:
jamesgi...@xxxxxxx wrote:...
[The Standard] doesn't usually say anything about memory layout as
such. However, since SEQUENCE derived types may be used in COMMON
and the components be storage associated through that COMMON with
non-derived-type variables, it's hard to imagine how it would be
implemented without actually being in the order declared.
Depending on what restrictions are imposed on COMMON, it might be
feasible for the compiler to automatically re-order to avoid alignment
issues, as long as that re-ordering were applied consistently across all
contexts.
Yes, as long as the required semantics are accomplished, the standard
otherwise permits implementations to do anything they like. That's
the "as-if" rule. However, as I said, in this case it's difficult to
imagine how to reliably reorder things. Given that COMMON, at the
very least, is likely to involve independently compiled externals, how
does the compiler manage to communicate all the necessary info?
Consider:
type T1
sequence
real :: comp1
double precision :: comp2
integer :: comp3
complex :: comp4
end type
type(t1) :: TVar
complex /aBlock/ Tvar
In another program unit, the COMMON might be declared:
real :: var1
double precision :: var2
integer :: var3
complex :: var4
common /aBlock/ var1, var2, var3, var4
Now these have to interoperate in the obvious way. Each VAR should be
storage associated with the COMP of the same number. Now you might
argue that if the compiler reorders both TYPEs and COMMONs the same
way, what's the problem? But both the above have to interoperate
with:
integer :: ivar(6)
common /aBlock/ ivar
And IVAR(1) in this program unit must be storage associated with VAR1
in the last program unit, IVAR(2) is associated with half of VAR2,
etc. IVAR(4) in this program unit corresponds to VAR3 in the last,
and TVAR%COMP3 in the first program unit. These can interoperate,
since they are also the same type.
But there's even more going on. If I assign a value to IVAR(6) in
this program unit, that causes VAR4 in the last program unit and TVAR
%COMP4 in the first program unit to become undefined. But is doesn't
cause any of the other variables to become undefined. This kind of
pattern applies to all elements of the IVAR array except IVAR(4) -
assigning to any of them causes a corresponding variable in the middle
program unit to become undefined, and also one of the components of
TVAR in the first program unit.
Similar complexities can arise in different ways. Suppose you have a
program unit that defines two derived types: one with a REAL and a
DOUBLE PRECISION component and the other with an INTEGER and a COMPLEX
component. A COMMON with one of each of those types in it should also
interoperate with the original. Additional examples are not hard to
imagine.
Given that the program units might be independently compiled external
procedures, what set of rules for reordering COMMON and/or SEQUENCE
derived types could manage? Certainly having different rules for
reordering if external procedures are present than otherwise would
introduce a good deal of compiler complexity. I suspect you'll not
see SEQUENCE types reordered in actual implementations.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
.
- Follow-Ups:
- Re: Warning: The structure contains misaligned fields
- From: Craig Powers
- Re: Warning: The structure contains misaligned fields
- References:
- Warning: The structure contains misaligned fields
- From: blitheli
- Re: Warning: The structure contains misaligned fields
- From: Gordon Sande
- Re: Warning: The structure contains misaligned fields
- From: blitheli
- Re: Warning: The structure contains misaligned fields
- From: Craig Powers
- Re: Warning: The structure contains misaligned fields
- From: jamesgiles@xxxxxxx
- Re: Warning: The structure contains misaligned fields
- From: Craig Powers
- Warning: The structure contains misaligned fields
- Prev by Date: Re: Warning: The structure contains misaligned fields
- Next by Date: Re: Warning: The structure contains misaligned fields
- Previous by thread: Re: Warning: The structure contains misaligned fields
- Next by thread: Re: Warning: The structure contains misaligned fields
- Index(es):
Relevant Pages
|