Say I have a C function void foo(int* val) for which I have written the following Fortran C binding (F2008 standard conforming, I hope):
use, intrinsic :: iso_c_binding
...
subroutine foo(val) bind(c)
integer(kind=c_int), intent(inout) :: val
end subroutine
The implementation of the C function void foo(int* val) treats the argument val as optional by checking the pointer for NULL. My question is: How can I set up and/or use the Fortran C binding subroutine foo(val) such that it supports val to be optional, i.e. such that actually a null pointer is passed to the C function?