Quantcast
Channel: Recent posts
Viewing all articles
Browse latest Browse all 19

Passing strings, C and Fortran 11.x vs 12.x differences?

$
0
0

  Behaviour of passing strings between C and Fortran is changing?
  Following code gives different results between 11.x and
  12.x versions if icc/ifort.  C main calling Fortran sub passing in strings/ints.

  Maybe 11.x was letting something slide that wasn't legit.
  I know there are C bindings now in Fortran but this is
  old code that I've stripped down to basics
  Would character(len=1)  array(N) be the answer?

  ifort/icc 11.1 20100806  has no problem with this.
  ifort/icc 12.1.5 20120612 gives in mainfort:

Address of i2a           7FFFD6815FA8
 i2a           22
Address of rseed            7FFFD6815FA0
 rseed           -1
Address of f1c            7FFFD6815F00
forrtl: severe (408): fort: (18): Dummy character variable 'F1C' has length 80 which is greater than actual variable length 0

 
top.c

#include <stdio.h>
#include <string.h>

void mainfort_(char f1c[80], char f2a[80],
              int *i1c, int *i2a, int *rseed);

int main (int argc, char *argv[])
{
  char f1c[80],  f2a[80];
  int i1c, i2a;
  int rseed;

  strcpy(f1c, "long string number 1");
  strcpy(f2a, "longer string number 2");

/* This is a print to see if we execute this */
  printf("This is the main in C\n");

  rseed = -1;
  i1c=strlen(f1c);
  i2a=strlen(f2a);

printf("i1c %d\n",i1c);
printf("address of i1c %p\n",&i1c);

printf("i2a %d\n",i2a);
printf("address of i2a %p\n",&i2a);

printf("rseed %d\n",rseed);
printf("address of rseed %p\n",&rseed);

printf("address of f1c, f2a %p, %p\n",&f1c,&f2a);
printf("%s %s\n",f1c,f2a);

  mainfort_(f1c, f2a, &i1c, &i2a, &rseed);

}

mainfort.f90
subroutine mainfort(f1c, f2a, i1c, i2a, rseed)
  implicit none
  character*80:: f1c, f2a
  integer :: i1c, i2a, rseed

  print *,"In mainfort---"
  print "(A,Z)", "Address of i1c ",loc(i1c)
  print *, "i1c ",i1c

  print "(A,Z)", "Address of i2a",loc(i2a)
  print *, "i2a ",i2a

  print "(A,Z)", "Address of rseed ",loc(rseed)
  print *, "rseed ",rseed

  print "(A,Z)", "Address of f1c ",loc(f1c)
  print*, 'f1c  ', f1c(1:i1c)
 
  print "(A,Z)", "Address of f2a ",loc(f2a)
  print*, 'f2a  ', f2a(1:i2a)

 print "(A,Z)", "Address of rseed ",loc(rseed)
 print *, "rseed ",rseed

end subroutine mainfort


Viewing all articles
Browse latest Browse all 19

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>