I am writing this Fortran to C interface which is auto generated from a script and I stumbled upon a very annoying limitation where a variable from the argument list shares the same name as a Fortran intrinsic (size
) thus causing all sorts of problems.
subroutine foo(dimTags, size, ierr)
use, intrinsic :: iso_c_binding
integer(c_int), dimension(:), intent(in) :: dimTags
real(c_double), intent(in) :: size
integer(c_int), intent(out) :: ierr
print*, size(dimTags, kind=c_size_t), size
end subroutine foo
Changing the variable names is not really an option, so my next best solution was to just create a local function for size
to avoid the name conflict and wrap it around an interface
for easy usage.
function fsize_sizet(o) result(sz)
integer(c_int), dimension(:), intent(in) :: o
integer(c_size_t) :: sz
sz = size(o, kind=c_size_t)
end function fsize_sizet
That is perfectly fine, but my question is, is there a simpler, hopefully more elegant way of doing this?
PS I recall seeing a post on this Discourse about how it would be nice to allow for renaming (=>
) of the Fortran intrinsics, but AFAIK that is not a thing yet.