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

Passing array of strings to Fortran

Martin__Paul
New Contributor I
2,195 Views
I am calling a 3rd party Fortran DLL from C. The manual describes a function whose argument include: character units(*)*(*)

This I understand refers to a variable-length array of strings.


In this situation does Fortran expect a string length argument for each of the strings in the array? If so should the length arguments be passed individually or also in an array?

Thanks in adv.

0 Kudos
4 Replies
Steven_L_Intel1
Employee
2,195 Views
Not "variable length" - what you have here is an array of strings all the same length. What would be passed is the starting address of the strings and, as a "hidden" parameter after all the explicit arguments, the string length passed by value (and of type size_t, not int!) I'm not immediately certain how you would declare such a thing in C - it is not the same as an array of strings in C which is actually an array of pointers.
0 Kudos
Martin__Paul
New Contributor I
2,195 Views
Thanks. The problem is the library I am calling from C is 3rd party so I can't change its interface. I've tried all the standard things like C-style arrays but as you point out this is not of the same type. Any suggestions gratefully received!
0 Kudos
Steven_L_Intel1
Employee
2,195 Views
I was not suggesting you change the third-party interface. I was explaining how you would call this from C. In the simple case of a single argument that is this CHARACTER(*)(*) array, it would be something like:

fsub(char * string, size_t string_len)

where "string" is a series of fixed-length strings (not nul-terminated). Perhaps you can declare it as something like:

char[40][10]

assuming 10 elements of 40 characters each, but my C is rusty enough that I am not sure - this itself may end up as an array of pointers which you don't want. Maybe char[40*10] and fill it in as needed.
0 Kudos
Martin__Paul
New Contributor I
2,195 Views

The second suggestion worked - indeed the point about char[][] resolving to an array of pointers was correct. As it turned out the library expects strings up to length 8 characters, so I was able to pass a single char* containing the individual string components, e.g.:

char[] = "aaa bbb ccc ddd eee fff ";

This worked - thank you for the swift replies.

0 Kudos
Reply