- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am calling a 3rd party Fortran DLL from C. The manual describes a function whose argument include: character units(*)*(*)
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?
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.
Link Copied
4 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page