Calling METIS API(wrtten in C language) in fortran program

前端 未结 2 2020
甜味超标
甜味超标 2020-12-12 02:12

Over 2 weeks, I\'ve struggled to call one of the METIS library written in C from my fortran code. And, unfortunately, It doesn\'t seem to be a HAPPY END without your help. I

2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-12 02:31

    1. No, you cannot pass null(), that is a Fortran pointer constant. You must pass C_NULL_PTR from the module ISO_C_BINDING and the interface must reflect this. The dummy argument must be type(c_ptr), most probably with VALUE attribute. It may actually work because of the same internal representation, but I wouldn't count on it.

    2. No, if you pass some normal variable, you can pass it directly by reference. Just like normally in Fortran. If the interface is BIND(C), the compiler knows it must send a pointer.

      There is a new TS to update Fortran 2008, where you can define dummy arguments in the interoperable procedures as OPTIONAL. Then you can pass the null pointer just by omitting them. Gfortran should already support this.

    Note: Here I can see a much different C signature of your function, are you sure yours is OK? http://charm.cs.uiuc.edu/doxygen/charm/meshpart_8c.shtml

提交回复
热议问题