Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29008 Discussions

mixed programming problems with strings

pdehon
Beginner
242 Views

I try to call a C++-function by a Fortran program. In C++ I only receive the first character whatever combinations of VALUE or REFERENCE attributes are applied. What can be the reason?

Fortran looks like this :

interface

integer function fn(A)

!DEC$ ATTRIBUTES DLLIMPORT, DECORATE, ALIAS:'fntestlib2' :: fn

CHARACTER(5) A

end function

end interface

! Variables

integer res

res = fn('test')

C++ :

extern

"C"

{

__declspec

(dllexport)
int fntestlib2(char* s, unsigned int len_arg);

}

}

__declspec

(dllexport)
int fntestlib2(char* s, unsigned int len_arg)

{

return 42;

}

0 Kudos
1 Reply
Lorri_M_Intel
Employee
242 Views

I wasn't able to reproduce the failure you described using this program. Actually, I made two changes. In the Fortran program, I null-terminated the string, as:

res = fn('test'//char(0))

And, in the C++ program I output the string that was passed in, and it looked fine.

I assume there is a DLL involved here, based on the "dllimport/dllexport" directives; is there a chance your test is finding the wrong DLL?

- Lorri

0 Kudos
Reply