COMMON padding warning

Thomas Koenig Thomas.Koenig@online.de
Wed Oct 19 00:38:00 GMT 2005


On Tue, Oct 18, 2005 at 04:02:27PM -0400, Jakub Jelinek wrote:

> common /blk/ x, p
> integer, target :: x
> integer, pointer :: p
> end
> 
> gfortran warns on 64-bit arches:
> Warning: COMMON 'data' at (1) requires 4 bytes of padding at start
> 
> x is 4 bytes here, p is 8 bytes.
> Can anyone enlighten me:
> 1) why is x aligned up in the COMMON block rather than down
> 2) what's the purpose of this warning - is the user doing anything
>    wrong?  The C compiler certainly doesn't warn when it inserts
>    padding anywhere, it is just a part of the target's ABI

I'm sure somebody will correct me if I'm wrong, but here's my
understanding, from what I have gathered from c.l.f discussions
(mostly).

COMMONs are supposed to be contiguous in memory according to all
Fortran standards.  An implementation ("processor") that inserts
padding between variables in COMMON is in violation of the
various Fortran standards.

Many processors chose to ignore this, especially for RISC.
Conventional Fortran programming wisdom has therefore been to order
variables in commons in order of decreasing size (and therefore,
supposedly, alignment restrictions).

In principle, a processor could add code for accessing misaligned
commons by copying the value (using memcpy() or something like that)
to a temporary location before use, using the value and then storing
it back after use.  This could mean a large performance penalty,
and a prominent warning would probably be in order for this.

Basically, gfortran handles this the same way that a lot of
other Fortran compilers:  By warning if the user's code (which is
standard-conforming) cannot be handled by the compiler.



More information about the Fortran mailing list