This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Bug with ISO_C_BINDING on Mac OS?


Am 01.06.2013 14:14, schrieb Janus Weil:
Ok, using TYPE(c_ptr) here, too.

However, when the test case is updated accordingly (see attachment), I also end up with a valgrind error on Linux:

You didn't do what I proposed: You missed the VALUE for "f":

function bzReadOpen (bzerror,f,verbosity,small,unused,nUnused) bind (c,NAME='BZ2_bzReadOpen')
      use, intrinsic :: ISO_C_BINDING
      integer(c_int) :: bzerror
      type(c_ptr),VALUE :: f, unused
      integer(c_int),value :: verbosity,small,nUnused
      type(c_ptr) :: bzReadOpen
    end function

Without VALUE, it sometimes showed valgrind problems / segfaulted - and sometimes it didn't. Ignoring that real issue that you don't access what you want to access ...


And in a follow-up email:

Ok, in fact it works (on Linux) if I remove the VALUE attribute for
all arguments (updated code attached). Will check if this also fixes
it on Mac OS ...
Seems like it does. Thanks for the help and sorry for the noise ...

But that shouldn't work. One cannot simply add VALUE attributes at will - it has to match what the code expects:

For verbosity and small it expects an integer - and not a pointer to an int. And for "f" it expects a pointer (void * or FILE *) and not a pointer to a pointer (void** or FILE **). Only for "bzerror" removing the VALUE is fine as "integer(c_int)" matches "int *". [Actually, there was (correctly) never a VALUE attribute for bzerror - thus, one cannot remove it ;-)] - And for trailing unused arguments, it does not really matter one one passes, but if one want to pass a C_NULL_PTR and an "int", both also need the VALUE attribute.

Tobias


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]