From Kurt.Hornik@ci.tuwien.ac.at  Thu Sep  9 09:14:54 1999
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Thu, 9 Sep 1999 10:14:54 +0200 (CEST)
Subject: Fortran character strings
In-Reply-To: <199909061254.NAA00597@toucan.stats.ox.ac.uk>
References: <199909061254.NAA00597@toucan.stats.ox.ac.uk>
Message-ID: <14295.27774.194390.155680@fangorn.ci.tuwien.ac.at>

>>>>> Prof Brian Ripley writes:

> Has anyone ever successfully used Fortran character strings with R?
> ?Foreign says

>          R              C                  Fortran
>       integer       int *              integer
>   ....
>       character     char **            [compiler dependent]

>      Character strings are passed as C arrays of character
>      strings to Fortran: the first string may be usable if
>      its length is passed separately.

> and I have been taking a look. The linkage sends char ** to Fortran.
> On the other hand, INTPR and DBLEPR assume Fortran character strings
> are char *.  On all my systems DBLEPR works and .Fortran does not, but
> I do know of one compiler (Watcom Fortran for Windows NT) where the
> linkage really is equivalent to char **.

> Fortran in S takes the first string in a character vector and passes
> that as char * (except on the Watcom-compiled Windows version), as far
> as I can deduce without the source code.

> I think we should either ban character strings in .Fortran or follow
> the S prototype unless someone has a way around this.  With different
> compilers on the same platform having different conventions whatever
> we do (except a ban) will be compiler-dependent.

> Any suggestions?

Hmm ... this is someone not knowing what is going (i.e., me) commenting
on this.

I touched this once when porting Rousseeuw's cluster routines to R,
maybe the thread is in the r-core archives.  I seem to recall that
someone told me that this was really a compiler-specific issue and hence
could/should not be part of the API.  (In the specific case, it was a
0/1 string so I found a different solution.)

(Btw, why do we map integer to int * and not long *?)

-k

PS.  A comment on ?.External:  We have

         list          void * (SEXP *)
         other         void * (SEXP)

I think this (showing the alternative in parenteses) may be confusing.
Shouldn't we show the preferred method in the table and mention the
alternative somewhere in the text following?

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Fortran character strings
Kurt Hornik