Currently, gfortran automatically aligns data in COMMON blocks, as in the
following example:

implicit none
integer(kind=4) :: n
real(kind=8) :: p
common /foo/ n,p
end

This gives the warning:

COMMON 'foo' at (1) requires 4 bytes of padding at start

This automatic padding can result in unexpected results, as demonstrated by the
following code:

subroutine one()
 implicit none
 integer :: n1,n2,n3,n4
 common /foo/ n1,n2(2),n3,n4
 print *, n3, n4
end subroutine one

program prog
 implicit none
 integer :: n1,n2,n3
 real(8) :: r1
 common /foo/ n1,r1,n2,n3
 n2 = 2
 n3 = 3
 call one()
end program prog

The output of this program is "0 2" instead of "2 3".

Therefore gfortran should have an option to suppress automatic alignment.
Preferrably this option should be enabled by default.

See also http://gcc.gnu.org/ml/fortran/2008-09/msg00221.html


-- 
           Summary: alignment of data in COMMON blocks
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: janus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37486

Reply via email to