Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29277 Discussions

compiler alignment in C-Fortran interface

hyoga
Beginner
475 Views
I would like to implement a library (in C) with C-fortran interface that use derived-types as argument of some functions. If I explicitly add padding in my structure can I be sure that I will not have alignment problems using the structure in a fotran program that has been compile with Intel fortran compiler (while the C library functions have been compiled with GNU compiler gcc)?

for instance, let's consider the folowing implementation :
###############################################################
########### file Cinclude.h:

struct mystr {
double r8;
int i4;
char pad[4];
char chain[128];
};

############ file F90include.h :

TYPE mystr
SEQUENCE

real (kind=8) :: r8
integer (kind=4) :: i4
character (len=4) :: pad
character (len=128) :: chain
END TYPE mystr

############# library function definition (in C) (compile with gcc)
include "Cinclude.h"

void init_str_(struct mystr* s_init) {
...
}

############# fortran program that call library (compile with Intel Fortran compiler)

PROGRAM TEST
implicit none
include 'F90include.h'

type(mystr) :: s_main

call init_str(s_main)
write(*,*) s_main%chain

END PROGRAM
###############################################################

Nicolas
0 Kudos
1 Reply
TimP
Honored Contributor III
475 Views
This looks like a good shot. 16-byte alignments for objects of 13 bytes or more, are the most which either compiler should use by default.
As you have set SEQUENCE, you might set __attribute__((packed)) and consider the advice in 'info gcc' under -Wpacked.
0 Kudos
Reply