Passing character from gnu C (gcc) to gfortran includes NUL terminator
Posted on 2010-08-18
When passing a character array from gcc to gfortran the string contains the NUL character which terminates the string in C, but not in FORTRAN.
On the HP UNIX system the NUL did not get sent when passing it across, but in the GNU C/Fortran world on Linux it is passed which is causing problems for programs I am trying to convert to Linux.
I can, and have written a subroutine which will strip this NUL so I have a solution, however I believed that by using ISO_C_BINDING and then passing the string that it would not send the NUL across, which would have been a nicer solution.
Do you know if using ISO_C_BINDING from gfortran and then having C/gcc pass the characters that it ought not send the NUL or have I misinterpreted something?
If this is true do you have some working code to show this? I tried it and it still sent the NUL, so I can't see the point in using ISO_C_BINDING and C_CHAR?
(p.s. I am using gcc 4.4.? and in RedHat Linux if that is of any importance.)