alignment/padding when mixing C struct and fortran 90 derived type

burlen burlen@apollo.sr.unh.edu
Sun Jan 20 15:50:00 GMT 2008


Hi all,

currently I have some C code that will call a fortran 90 subroutine. In 
the C portion I have defined:

struct record
{
  int id;
  int dataLen;
  int *pFile;
  double *data;
  int ofs;
};

while in the fortran code I have defined:

module GGCM
type  record
    integer :: id
    integer :: dataLen
    integer, pointer :: pFile
    real*8, pointer :: data
    integer :: ofs
    end type record
contains
end module

 From a C code I will declare an instance of record, initialize it and 
call a fortran subroutine which is defined like so

subroutine manipulateCStruct( kot )
  use  GGCM
  implicit none

  type(record) :: kot

  kot%id = kot%ofs
  kot%pFile = kot%ofs ! this should modify file which is in main.cpp
  kot%ofs = 128

  end subroutine

These will be compiled and linked using gcc, and gfortran.  All is fine, 
and works as I'd like with out compiler optimization. My question is 
will I be safe passing above struct when compiler optimizations are 
enabled? I have the intuition that so far as the compile lines use the 
identical optimization flags, then all will be OK. But I'd like to 
confirm if possible gfortran and gcc use same alignment/padding 
optimizations.

Thanks in advance
Burlen






More information about the Gcc-help mailing list