Software Archive
Read-only legacy content
17061 Discussions

Character strings when calling Fortran from C++

Intel_C_Intel
Employee
286 Views
How can I call the following Fortran subroutine:

subroutine runcmd(command)
character*256 command
...
Do something ....
...
return
end

from C++ (VC++ 6)

When calling it like this:

extern "C" { void __stdcall RUNCMD(char* command); }
RUNCMD("This is at test");

I get the following compiler error message:

unresolved external Symbol _RUNCMD@4

I now that it has something to do with a hidden length argument,
passed with characters, but don't know what's to do.

Thanks in advance
0 Kudos
1 Reply
Jugoslav_Dujic
Valued Contributor II
286 Views
Yes, hidden length argument is passed (by default, immediately after string argument.) You should either add and additional length argument in C declaration:
extern "C" { void __stdcall RUNCMD(char* command, int len); }


or adjust the Fortran routine so that it doesn't expect length:
subroutine runcmd(command) 
!DEC$ATTRIBUTES REFERENCE:: command 
character*256 command


HTH
Jugoslav
0 Kudos
Reply