- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
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
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
As you have set SEQUENCE, you might set __attribute__((packed)) and consider the advice in 'info gcc' under -Wpacked.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page