Why is ISO_C_BINDING

I am working on some fortran-call-C code and do not understand how to use the iso_c_binding module.

I have fortran and C interfaces working successfully without iso_c_binding, and the question is whether I should explicitly bind functions and variables. For example, this works:

program testprog
...
interface
  subroutine c_parser(param)
    integer, intent(in) :: param
  end subroutine
end interface

integer :: a
call c_parser(a)
..
end program

/****************/

void c_parser_ (int* param)

So, add an underscore to the C function, write an interface for it, and call it from the fortran program. I do not use pointers or allocatables, all my code has ints, char, float and boolean, which need to be transferred from the fortran routine to C.

What is the purpose of iso_c_binding? Are there any errors? As an example, this mentions a caveat when using strings through bindings (see Part “Unfortunately, at least GNU and Intel compilers, expression”).

+4
2

"" Fortran. - , . , .

ISO_C_BINDING - , , . , , , ( ), .

, Fortran , , C. - , , Fortran.

C , . USE ISO_C_BINDING , .

BIND (C) , , , C Fortran. ( C) . , .

, , .

( " ..." fortran wiki , Fortran - C , LEN = 1 Fortran, C char.)

Fortran 2003, , C Fortran 2003. , , .

+10

ISO_C_Binding Fortran C . , .

+4

All Articles