This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Type Alignment


I have been helping the OpenMPI project with some
of their Fortran issues and a problem with determining
the alignment of basic types has come up.  Currently
they are testing for alignment in two ways based on
F77 and F90.  Unfortunately the tests give different
answers and I'm not sure which test is correct (if either).

The F77 test places variables in a common block with an assortment
of characters to force padding to align the types.  It then
calls a C function with the variables in the common block
and determines alignment from the addresses.

The F90 test is similar except that it uses a derived type.

I'm including portions of the F77 and F90 code.  Helpful
comments would be most appreciated.

Thanks,
Craig

-------- F77 --------------

      subroutine align_f77()
      external ALIGN
      REAL*8  w,x,y,z
      CHARACTER a,b,c
      common /foo/a,w,b,x,y,c,z
      call ALIGN(w,x,y,z)
      end

-----------F90 ---------------
!
! This code actually tests with both a common block
!  and a derived type.  They appear to give different
! answers
!
module stuff
  type stuffed
    character :: a
    real*8 :: w
    character :: b
    real*8 :: x
    real*8 :: y
    character :: c
    real*8 :: z
  end type stuffed
end module stuff

subroutine align_f90()
  use stuff
  external ALIGN, align_all
  type(stuffed) :: t
  real*8 ::  w,x,y,z
  CHARACTER a,b,c
  common /foo_c/ a,w,b,x,y,c,z
  call ALIGN(w,x,y,z)
  call ALIGN(t%w,t%x,t%y,t%z)
  call align_all(a,w,b,x,y,c,z)
  call align_all(t%a,t%w,t%b,t%x,t%y,t%c,t%z)
end subroutine align_f90


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]