Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scalar argument may not be associated with a dummy argument #1074

Closed
naromero77 opened this issue Mar 13, 2020 · 3 comments
Closed

scalar argument may not be associated with a dummy argument #1074

naromero77 opened this issue Mar 13, 2020 · 3 comments

Comments

@naromero77
Copy link

naromero77 commented Mar 13, 2020

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
@LKedward
Copy link

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.

Change:

character(len=len(command)+1) :: command_c

to:

character(len=1,kind=c_char) :: command_c(len(command)+1)

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.

@naromero77
Copy link
Author

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.

@naromero77
Copy link
Author

Original code is fixed and test passing with multiple compilers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants