These are chat archives for Fortran-FOSS-Programmers/General-Discussion

26th
May 2017
Jacob Williams
@jacobwilliams
May 26 2017 00:59
Thanks @nncarlson ! I'm still not sure what is "legal" and what isn't with C_LOC but I like this approach (at least it works on both ifort and gfortran).
Neil Carlson
@nncarlson
May 26 2017 15:10
It also works for NAG. Using C_LOC on a polymorphic variable is an error with NAG, and I too am not sure what is "legal". I got mixed signals from FortranFan and Steve Lionel (your Intel forum link).
Stefano Zaghi
@szaghi
May 26 2017 19:50
@jacobwilliams @nncarlson Interop-C is still a mystery for me... can I ask some details about when/where the box wrapper plus c_loc turn to be useful? Cheer
Jacob Williams
@jacobwilliams
May 26 2017 21:20
@szaghi I'm doing some experiments using it as a way to call object-oriented fortran code from Python. I'll try to post about it soon.
Neil Carlson
@nncarlson
May 26 2017 21:49
My use case (https://github.com/nncarlson/yajl-fort/blob/master/src/yajl_fort.F90) involved a C library that needed call back functions, which I implemented in Fortran. One of the arguments to a call-back was a user-supplied void pointer to "context data" that the call-back needed. It's a pretty standard approach in the C world. My ideal call-back was a type bound procedure of a polymorphic type with data components of the type providing the necessary context data. To get this to work with the C library, I passed the c_loc of a box wrapper around the polymorphic type pointer as the "context data". The function, whose pointer I passed as the call-back, turned this pointer back to a box around the polymorphic type pointer, and then invoked the type bound procedure that was the actual call-back.
Not sure if any of that made sense -- perhaps it's better explained with an example.