Re: [Rd] Calling FORTRAN function from R issue?

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 06 Mar 2012 15:51:08 +0000

On 06/03/2012 06:28, Berwin A Turlach wrote:
> G'day Dominick,
>
> On Mon, 5 Mar 2012 19:21:01 -0500
> Dominick Samperi<djsamperi_at_gmail.com> wrote:

...

>> This is consistent with the interface prototype for the BLAS
>> routine zdotc contained in<R>/include/R_ext/BLAS.h, namely,
>>
>> BLAS_extern Rcomplex
>> F77_NAME(zdotc)(Rcomplex * ret_val, int *n,
>> Rcomplex *zx, int *incx, Rcomplex *zy, int *incy);
>>
>> [...]
>>
>> On the other hand, this is not consistent with the standard
>> FORTRAN definition for zdotc that is contained in
>> <R>/src/extra/blas/cmplxblas.f, where the first argument is
>> n, not ret_val.
>
> This seems to be indeed inconsistent and, presumably, a bug. Applying
> the attach patch to R's development version (compiles, installs and
> passes all checks with this patch), and changing in your code the line

As I said elsewhere in this thread, this really is very compiler-specific, and rather than being a bug, that header is not appropriate to the compilers used (it came from the days of f2c and Fortran compilers based on it such as g77).

I'll change the sources to follow your patch as I think it is much more likely to be correct these days, but also add a warning in the header. I don't think it is safe to call these functions from C without configure-testing the effect.

>
> F77_CALL(zdotc)(&ret_val,&n, zx,&incx, zy,&incy);
>
> to
>
> ret_val = F77_CALL(zdotc)(&n, zx,&incx, zy,&incy);
>
> produces the expected output.

-- 
Brian D. Ripley,                  ripley_at_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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue 06 Mar 2012 - 15:53:40 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 06 Mar 2012 - 16:50:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive