In Using python-ctypes to interface fortran with python, the answer mentions the following:
In Fortran, arguments are passed by reference. Fortran character arrays aren't null terminated; the length is passed by value as an implicit long int argument.
Is that part of the Fortran standard or a compiler specific implementation?
(If the answer could explain how to search the fortran standard that would be a big plus).
More specifically, I'm interested as to whether the following use of ctypes
to call a Fortran string function is valid because of the compiler or because it's part of the Fortran standard.
Here's the example Fortran string function:
function prnt(s) ! byref(s), byval(length) [long int, implicit]
character(len=*):: s ! variable length input
logical :: prnt
write(*, "(A)") s ! formatted, to remove initial space
prnt = .true. end function prnt
Here's how you could call this function with Python's ctypes
module:
>>> from ctypes import *
>>> test = CDLL('./test.so')
>>> test.prnt_.argtypes = [c_char_p, c_long]
>>> s = 'Mary had a little lamb'
>>> test.prnt_(s, len(s)) Mary had a little lamb 1
Notice in Fortran, there is only a single argument, the string. But secretly, when a function has a string argument, it appears that a second argument is present which is the length of the string.
Is this something I can assume is true regardless of the compiler because it is part of the Fortran standard?