- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It seems that even in Fortran 2018 that passing strings to and from Fortran from other languages is less than pleasant.
I have not put a lot of thought into it and have not tried this (yet), but why not simply convert the characters in a string into their ASCII (or other base) integer equivalents, and send between C (or other language) and Fortran via a 1D integer array?
For example, instead of trying to send "This is a string" between the two languages, why not send
(84, 104, 105, 115, 32, 105, 115, 32, 97, 32, 115, 116, 114, 105, 110, 103)
back and forth (of course using the appropriate routines in C [or other language] and Fortran to do the character to integer conversions, parsing of the string, connotation of characters, etc.)?
Could it be that simple, or are there unforeseen pitfalls?
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Post-fixing a literal with C declares the Fortran string to be C compatible.
The variable STRING shows a box in place of the NULL character.
To pass this on to a C/C++ function, use TRIM(string) to remove the trailing spaces.
Jim Dempsey
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page