I'm having to write a subroutine that can be called both by C and by Fortran. This subroutine takes a file name as one of its arguments. I know that to interoperate nicely with C, the ISO C binding recommends using character arrays for interoperation.
The question I have is: is there such a thing as a character array literal that's easy to write? I have a subroutine like this:
subroutine my_sub(char_array)
use iso_c_binding, only: c_char
char(kind=c_char, len=1), dimension(:), intent(in) :: char_array
...
end subroutine my_sub
Is it possible to invoke this with something like:
call my_sub('Hello World!')
Or do I have to do something horrible like:
call my_sub((/ 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!' /))
My main issue seems to be that it doesn't like the assumed-shape array and that giving it a set (large) size also outputs all the garbage memory that happens to get picked up afterwards.
Is there a better way of doing this?