From ripley@stats.ox.ac.uk  Thu Sep  9 09:28:24 1999
From: ripley@stats.ox.ac.uk (Prof Brian D Ripley)
Date: Thu, 9 Sep 1999 09:28:24 +0100 (BST)
Subject: Fortran character strings
In-Reply-To: <14295.27774.194390.155680@fangorn.ci.tuwien.ac.at>
Message-ID: <Pine.GSO.4.05.9909090916450.4120-100000@auk.stats>

On Thu, 9 Sep 1999, Kurt Hornik wrote:

> >>>>> 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.)

It is compiler-specific, but there is a solution that works in 99% of the
cases that I have put in R-devel, with warnings.

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

How would I know?  (Actually, because it lets us use the C linakge, I
guess.)  We do assume that in building R, for things like eigen. I noted
that f2c does have a configure check for this, and I think we probably
ought to find out at configure time what integer does map to and make
.Fortran cover this.

> 
> -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?

It is confusing. Actually all of them are mapped to void *, so I think we
should be giving SEXP * and SEXP. Thomas?

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
Prof Brian D Ripley