- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am not sure if anyone has posted this topic already, As I searched and have not been able to find, I post my question here.
I need to use the C to call Fortran to get a character string data, what I prefer is the string use the C type string and pass
by reference, so that I do not have to use the additional argument about the string length. What I did is:
by reference, so that I do not have to use the additional argument about the string length. What I did is:
Fortran:
=======
SUBROUTINE GETSTRING(ASTRING)
!DEC$ ATTRIBUTES C, ALIAS '_GETSTRING' :: GETSTRING
CHARACTER(132) ASTRING
!DEC$ ATTRIBUTES REFERENCE :: ASTRING!Assignment data to ASTRNG
ASTRING(1:1) = 'A'
!AT THE END OF THE STRING, WILL ADD CHAR(0) TO ASTRINGRETURN
END
C PART CODE
===========void GETSTRING(char *string);//The following is the calling statement
char* astring = "Initial value of astring";
GETSTRING(string);
.....
Result
======
When C called Fortran, the initial value of astring is passed into the Fortran correctly, when
Fortran tried to modify the ASTRING (THE STATEMENT TO SET THE FIRST CHARACTER TO BE 'A'), the
program crashed, and says "access violation".
======
When C called Fortran, the initial value of astring is passed into the Fortran correctly, when
Fortran tried to modify the ASTRING (THE STATEMENT TO SET THE FIRST CHARACTER TO BE 'A'), the
program crashed, and says "access violation".
any experience on using this will be appreciated.
David.
Link Copied
2 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You must provide the additional length argument on the C side, to support Fortran CHARACTER type, even if you don't use it. If you want to use non-standard code, you could declare an array of single byte integers on the Fortran side, thus avoiding use of the length argument.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the message. I am not sure if your reply conflicts with the statement provided in the user guide, In thetable named"Effect of ATTRIBUTES Options on Character Strings Passed as Arguments" (MIXED Programming Part),
It states that when "String with REFERENCE option", the call will be
"Passed by reference, no length " therefore, I take itthatthere should beno length needed.
Regards,
David

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