This section describes passing atoms as pointers to fixed-length, blank-padded arrays of characters. This is the way to pass atoms as strings between Prolog and Pascal or FORTRAN. See fli-p2f-atm-spc for how to pass atoms as null-terminated strings between Prolog and C.
Implementation note: The foreign interface makes some assumptions about how string parameters are handled in Pascal and FORTRAN compilers. If a given Pascal or FORTRAN compiler has different conventions for the handling of string parameters, the interface will not work. The conventions are:
- A string result is represented by a pointer to the character array followed by its size. These two values are passed before all the other arguments.
- Other string parameters are also represented by a pointer to the characters and a size. In this case the pointer occupies the normal position in the argument list, and the size is passed after all the other arguments.
Prolog: +string(N) C: Not supported Pascal: type stringN = packed array [1..N] of char; var x: stringN FORTRAN: character*N
The argument must be instantiated to an atom, otherwise the call will signal an error. A character array, containing a copy of the characters of the atom, is passed by reference to the function. The text is truncated on the right or padded on the right with blanks to length N.
Note that the Pascal parameter is call-by-reference (var), the same as
for the -string(
N)
case below.
Prolog: -string(N) C: Not supported Pascal: type stringN = packed array [1..N] of char; var x: stringN FORTRAN: character*N
A pointer to a character array of length N, initialized to all blanks, is passed to the function. It is assumed that the function will fill in this array. When the function returns, the atom that has the printed representation specified by the character array is unified with the corresponding argument of the Prolog call.
Trailing blanks in the character array are ignored. Thus if the
foreign function sets a character array of length 6 to atom
,
Prolog will convert the result to the atom atom
. Leading blanks are
significant: if the foreign function returns this
, the resulting
atom is ' this'
.
The argument can
be of any type; if it cannot be unified with the returned atom, then
the call fails. If the function does not fill in the character
array, then the result is the null atom ''
.
Prolog: [-string(N)] C: Not supported Pascal: Not Supported FORTRAN: character*N function
This argument specification is valid only for FORTRAN. The FORTRAN function result is initialized to a blank-filled character array of length N. It is assumed that the function will fill this array. The atom that has the printed representation specified by the character array is unified with the corresponding argument of the Prolog call.
Trailing blanks in the character array are ignored, as for
the -string(
N)
case above.
The argument can be of any type; if it cannot be unified with the returned
atom, then the call fails. If the function does not fill in the character
array, then the result is the null atom ''
.