(j3.2006) Questions and ideas about writing bind(c) interfaces
Malcolm Cohen
malcolm
Sun Sep 27 02:22:50 EDT 2015
<<<
1. Conversion of actual arguments corresponding to by-value dummy
arguments of a "wider" kind.
>>>
Yes, Fortran does not have argument coercion. Argument coercion is
certainly convenient at times, but it also hides mistakes (yes, even if you
restrict it to "widening only"). So there are disbenefits as well.
I would also disagree that the dummy possessing the VALUE attribute would be
a good signal to turn such a feature on. One would imagine that INTENT(IN)
would be more to the point. But that would have been incompatible with
Fortran 90 and 95, not just Fortran 2003.
The purpose of interoperability is not to let people write C programs using
the Fortran compiler.
<<<
2. By-reference TYPE(*) vs by-value C_PTR
>>>
There are various subtle differences hers, like TYPE(*) does not require
that the object have the TARGET attribute. C_PTR does.
Considering this and all the other issues that arise, it seems reasonable to
use a wrapper to do this kind of thing.
Maybe there is something clever we could do that would only have good
effects, but it's not obvious.
<<<
3. No way to describe "const int *" in Fortran interfaces using C_PTR
"const int *" in C means that the target of the pointer can't change,
>>>
As I recall, the meaning is subtly different. More like "cannot be changed
via that pointer" I think. But anyway...
...there is no need to worry since "int *" and "const int *" have the same
representation. So just ignoring the const when making the Fortran
interface is fine.
<<<
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".
.......................................................
All the above my opinion only. Others' MMV.
Cheers,
--
........................Malcolm.
More information about the J3
mailing list