- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am trying to call a C subroutine with an indefinite number of arguments from a Fortran code. I have written something that work ok when using gcc/gfortran (various versions) but I get a segfault with icc/ifort. Here is a simplified version of my code which reproduces the segfault with intel compiler v14 and v15_beta.
The C routine
#include <stdarg.h> #include <stdio.h> void va(int in, ...) { int *out; printf("The input value is: %2d\n",in); va_list varg_list; va_start(varg_list, in); out = va_arg(varg_list, int*); *out = in; va_end(varg_list); }
The Fortran calling code
program vaf use iso_c_binding integer(c_int), target :: in, out interface subroutine va(in, out) bind(C) use iso_c_binding integer(c_int), value :: in type(c_ptr), value :: out end subroutine va end interface in = 15 call va(in, c_loc(out)) write(*,'("The output value is: ",i2)')out stop end program vaf
I don't really know whether this code is compliant or not because I couldn't find much info about this topic on reference books nor on the net. Therefore I can't really tell whether this is a compiler bug or just a broken code. Can anybody help?
Thanks,
Alfredo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See section 15.3.7 of the Fortran 2008 standard (or see 15.2.6 of the Fortran 2003 standard):
"NOTE 15.20
The C language allows specification of a C function that can take a variable number of arguments (ISO/IEC
9899:1999, 7.15). This part of ISO/IEC 1539 does not provide a mechanism for Fortran procedures to
interoperate with such C functions."
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
See section 15.3.7 of the Fortran 2008 standard (or see 15.2.6 of the Fortran 2003 standard):
"NOTE 15.20
The C language allows specification of a C function that can take a variable number of arguments (ISO/IEC
9899:1999, 7.15). This part of ISO/IEC 1539 does not provide a mechanism for Fortran procedures to
interoperate with such C functions."
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Mecej4,
thanks for your prompt response. This definitely answers the question.
Kind regards,
Alfredo
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page