CHARACTER variables

CHARACTER variables

In this section:

Fortran character arguments are fixed length and padded with space characters. In order to determine the length of a character argument, the FTN95 compiler passes the length of the string as an extra argument at the end of the argument list for the subroutine/function. If more than one character argument is passed, then the lengths are passed in the order in which the character arguments appear in the argument list. For example:

SUBROUTINE COMPARE(STRING1, STING2)
CHARACTER (LEN=*)::STRING1, STRING2
.
.
END

This subroutine would have the following C/C++ prototype:

extern "C" COMPARE(char *s1,char *s2,int l1,int l2);

where l1 and l2 are the lengths of the two strings s1 and s2 respectively. In order to call COMPARE from within a C/C++ program, the programmer must pass the lengths of the two strings so the call would look something like this:

char *str1, *str2;
.

.
COMPARE(str1, str2, strlen(str1), strlen(str2));

 

 

Basket
Empty
 
Copyright © 1999-2024 Silverfrost Limited