You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code snippet is extracted from a much large DOE code. It compiles with gfortran, pgi, (old) flang, but f18 gives:
flang -c -Mfree os_reduced.f
os_reduced.f:18:11: error: Whole scalar actual argument may not be associated with a dummy argument 'command=' array
ret = system_c(command_c)
^^^^^^^^^^^^^^^^^^^
/scratch/naromero/opt/spack/linux-ubuntu18.04-westmere/gcc-7.4.0/f18-master-yxbvzyykz5e5e5mwvwact3dukjyyyqjm/bin/f18: semantic errors in os_reduced.f
I am copying and pasting the code below:
module os_m
use, intrinsic :: iso_c_binding
contains
!> Call command `command` using call to POSIX `system` routine.
subroutine system(command)
character(len=*), intent(in) :: command
character(len=len(command)+1) :: command_c
integer(c_int) :: ret
interface !int system(const char *command);
integer(c_int) function system_c(command) bind(c, name='system')
use, intrinsic :: iso_c_binding, only: c_int, c_char
character(len=1,kind=c_char), intent(in) :: command(*)
end function system_c
end interface
command_c(1:len(command)) = command
command_c(len(command)+1:len(command)+1) = c_null_char
ret = system_c(command_c)
end subroutine system
end module os_m
The text was updated successfully, but these errors were encountered:
I believe the type of command_c here is incorrect. It should be an array of c interoperable characters (see in your interface definition for system), as opposed to a Fortran string.
You will then have to copy the strings a character at a time I think, see s2c for example.
I can confirm that your original code also compiled without warning in latest intel fortran: I'm not sure why this isn't picked-up in the other compilers, so I may be missing something here.
Thanks for looking at the reduced test case. I have verified that your modified code works with Intel, Gfortran, and f18 compilers. At the moment, I cannot compile the full DOE science app because of this unrelated issue: #1020
Let us leave the issue open for now until I can get the application developer to fix it their code. But I will close it as soon as I can.
This code snippet is extracted from a much large DOE code. It compiles with gfortran, pgi, (old) flang, but f18 gives:
I am copying and pasting the code below:
The text was updated successfully, but these errors were encountered: