On 23/04/2017 7:53 PM, Rolf Turner wrote:
On 24/04/17 11:36, Duncan Murdoch wrote:
On 23/04/2017 6:18 PM, Rolf Turner wrote:
On 23/04/17 23:05, Duncan Murdoch wrote:
Looks like
extern void F77_NAME(mnnd)(double *, double *, int *, double *,
double *);
to me.
One more (I hope it's the last!) question:
One of my subroutines has an argument of type *logical*. There is no
logical type in C. So, since I am perforce using C-speak, I cannot
change "void *" to "void logical".
For questions like this, see Writing R Extensions section 5.2. "Logical"
in R is "int *" in C, and "INTEGER" in Fortran.
This is important: *there is no way to pass a Fortran "LOGICAL" from R
to Fortran*.
The issue is that different Fortran compilers store LOGICAL in different
ways. Some are equivalent to int with 0 for FALSE, all else for TRUE,
but not all are. So don't rely on it.
If you need to call a Fortran subroutine that takes a LOGICAL argument,
you need to write another Fortran subroutine that takes an INTEGER
argument. Then compute "arg NE 0" (or whatever the Fortran version is
for testing not equal to zero) and pass that to the original routine.
Hoo-boy!!! Some serious code-rewriting called for!
Thanks for setting me straight on this.
Is it possible that R CMD check could be set up to issue an error, or at
least a warning, if it finds "logical" or "as.logical" in the argument
lists of calls to .Fortran()?
The problem is at the other end. Passing an R logical is fine; it just
turns into an INTEGER on its way to Fortran.
I doubt if it is feasible to detect the problem in Fortran, but static
analysis keeps getting better, so I could be wrong now or in a while.
Duncan Murdoch
Seems like it would be a Good Idea if it is indeed possible.
cheers,
Rolf
______________________________________________
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel