This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Re: Bug with ISO_C_BINDING on Mac OS?
- From: Tobias Burnus <burnus at net-b dot de>
- To: Janus Weil <janus at gcc dot gnu dot org>
- Cc: gfortran <fortran at gcc dot gnu dot org>
- Date: Sat, 01 Jun 2013 14:41:07 +0200
- Subject: Re: Bug with ISO_C_BINDING on Mac OS?
- References: <CAKwh3qhf9MsyRHR6Zcs+OZrY_kei0YGfSAuPz2RW9wziR2B=sA at mail dot gmail dot com> <51A9DDB1 dot 7060502 at net-b dot de> <CAKwh3qjK1XgoPqiUqnEMWsSvgOz5EYAbtJW+_ffSyGfpE4bBTw at mail dot gmail dot com>
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