[Fortran-experiments] Bind(c) first experiences
Tobias Burnus
burnus@net-b.de
Wed Dec 20 21:14:00 GMT 2006
Hi,
Brooks Moses wrote:
> Tobias Burnus wrote:
>> Thirdly,
>> type(c_funptr), pointer :: pnter
>> is accepted, whereas NAG f95 gives me an error:
>> Error: test.f90, line 4: BIND(C) variable PNTER is a POINTER
>> (I think NAG's error message is a bit misleading.)
>>
>> I think this is prohibited; see F2003, 15.2.2 / 15.2.3:
>> "C_PTR and C_FUNPTR shall be derived types with private components."
>> "C1505 (R429) Each component of a derived type with the BIND attribute
>> shall be a nonpointer, nonallocatable data component with interoperable
>> type and type parameters."
>
> But C1505 is referring to components of the derived type (that is, to
> the parts that make up the type), not to variables of the type,
> whereas this is a variable of the derived type. Thus, that
> restriction doesn't apply.
You are of cause right.
> I'm not sure if there's some other rule that prohibits declaring
> pointers as bind(c) variables, and unfortunately I should probably be
> off to bed now rather than looking it up.
"15.2.4 Interoperability of scalar variables
A scalar Fortran variable is interoperable if its type and type
parameters are interoperable and it has neither the pointer nor the
allocatable attribute."
Prohibits it for scalar variables, but I wouldn't call "type(c_funptr)"
scalar, either -- or does it actually apply here?
In any case, combining the two rules, the following is invalid (NAG f95
complains also), but quietly accepted by gfortran:
module test
use iso_c_binding
type foo
integer, pointer :: p
end type
type(foo), bind(c) :: cp
real(c_double), pointer,bind(c) :: p
end module test
Thus: Speaks anything against adding a conflict bind_c <-> pointer?
* * *
Fourth item: Bind(C) variables are only allowed in modules
specification, as NAG f95 and g95 report:
Error: foo.f90, line 2: BIND(C) for P outside of a module specification part
Error: BIND(C) variable at (1) must be a MODULE variable
--------------
use iso_c_binding
real(c_double), bind(c) :: p
end
--------------
I think this is:
"15.3 Interoperation with C global variables
A C variable with external linkage may interoperate with a common block
or with a variable declared in the scope of a module. The common block
or variable shall be specified to have the BIND attribute."
* * *
I svnmerge.py-ed now the trunk (r119464:120078) into
fortran-experiments, leaving out the Paul's VALUE patch (r119461).
I did a regression test, which gave no regressions (except for
c_kind_params.f90 ) on x86_64-unknown-linux-gnu.
Tobias
More information about the Fortran
mailing list