(j3.2006) Questions and ideas about writing bind(c) interfaces

Cohen Malcolm malcolm
Mon Sep 28 04:35:41 EDT 2015


I don't think the aliasing issue is a particularly big deal.  "everything 
aliased to cp" has the TARGET attribute, and in many cases this will mean 
that a pointer will potentially have "escaped" at some time and therefore 
any procedure (whether you pass it cp or not) is going to potentially change 
it.

Giving everything the TARGET attribute is (IMO) the problem here, not some 
arcane facility for the user hinting that those things did not get modified.

So I think this is way too small a benefit for an ugly wart of a language 
feature.

Of course, if instead of declaring the dummy TYPE(C_PTR),VALUE you declared 
it TYPE(*),INTENT(IN) you would both
(a) remove the need for the TARGET attribute
(b) convey the intent.
Yes, that gets us back to the "TYPE(*) and C_PTR don't mix ideally without a 
wrapper" problem, but until someone comes up with a brilliant idea that does 
not introduce other problems I think we can live with this.

(Aside: it is hardly surprising that a library designed for use from C, a 
language with significantly different design goals, can be a little clumsy 
to call from Fortran, and does not enable all the optimisations that Fortran 
can usually do.)

Cheers,

-----Original Message----- 
From: Rafik Zurob
Sent: Monday, September 28, 2015 4:12 AM
To: fortran standards email list for J3
Subject: Re: (j3.2006) Questions and ideas about writing bind(c) interfaces

Hi Malcolm

> <<<
> It would be nice if iso_c_binding provided a const_c_ptr type and
> a conversion function to convert from const_c_ptr to c_ptr.
> >>>
>
> I disagree.  It would be a waste of time and effort, and being
essentially
> uncheckable would not improve reliability more than it disimproves the
user
> experience due to the annoyance factor arising when passing a "const"
> pointer to a procedure that does not modify the target, but does not
declare
> it to be "const".

I think it makes a difference in aliasing, similar to how intent(in) helps
improve the aliasing of Fortran dummy arguments.  If one is passing c_ptr
cp to function foo, there is currently no way of expressing in the Fortran
interface that foo will not change the target of cp via cp.  So one has to
kill everything aliased to cp.  With the const_c_ptr way, one wouldn't
have to kill anything on the call to foo.

Regards

Rafik

_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org
http://mailman.j3-fortran.org/mailman/listinfo/j3

________________________________________________________________________
This e-mail has been scanned for all viruses by Star.
________________________________________________________________________

-- 
........................Malcolm Cohen, Nihon NAG, Tokyo. 




More information about the J3 mailing list