Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

C interoperability scalar pointer

pat97269
Beginner
485 Views
Hi,
I have a question about the function c_loc() of iso_c_binding,
[bash]real(c_double),dimension(:), pointer :: temp1,temp2 allocate(temp1(f_sp%sizeknots)) allocate(temp2(f_sp%sizecoefs)) f_sp%knots=c_loc(temp1)[/bash]


what exactly is a associated scalar pointer, and why the compiler tolerate this instead of c_loc(temp1(1)) ?
Thanks
0 Kudos
1 Reply
Steven_L_Intel1
Employee
485 Views
The C_LOC here returns a TYPE(C_PTR) containing the location (address) of its argument. Since temp1 is a pointer and the dummy argument to C_LOC is not, you get the location of the first storage element of the thing pointed to by temp1, which would be the same as if temp1(1) was specified.

In Fortran 2003, C_LOC could be specified for "interoperable" arguments only, and temp1 is not that. But Fortran 2008 relaxed the rule to remove the requirement that the argument be interoperable. Intel Fortran does not check this requirement (and is not required to.)

An "associated scalar pointer" is a pointer to a scalar that is associated, since pointer arrays are not interoperable. Fortran 2003 lists that as one of the acceptable argument types for C_LOC, but Fortran 2008, as I said above, relaxes that.
0 Kudos
Reply