[R-pkg-devel] warning: type of ‘zhpevx_’ does not match original declaration [-Wlto-type-mismatch]

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Tue Jul 7 15:44:09 CEST 2020


On Tue, 7 Jul 2020 03:00:23 +0000
Pierre Lafaye de Micheaux <lafaye using unsw.edu.au> wrote:

>Should I just write something like (adding the middle instruction
>below to my existing code above)?:
>
>#ifdef FC_LEN_T
>typedef long long int FC_LEN_T;

No, I don't think that would help.

What _might_ help is adapting the incantation from [*] to redefine
FC_LEN_T to int on older GCC:

#if defined(__GNUC__) && __GNUC__ < 7
 /* Rconfig.h #define doesn't match the actual type
  * of hidden length argument in old gfortran */
 #define FC_LEN_T int
#else
 /* Otherwise we use the #define from Rconfig.h */
 #define USE_FC_LEN_T
#endif
/* Your code starts here */
#include <R.h>
/* ... */

Another option that _should_ help is rewriting zhpevxC in Fortran
2003 using its bind(c) feature. The C interoperability would ensure that
the resulting function is callable from C, while the fact that it's
written in Fortran should make it safe to call other Fortran functions:

subroutine zhpevxC(jobz, range, uplo, n, ap, vl, vu, il, iu, &
                   abstol, m, w, z, ldz, work, rwork, iwork, &
                   ifail, info) bind(c, name='zhpevxC')
 use, intrinsic :: iso_c_binding, only: c_char, c_int, c_double, &
                                        c_double_complex

 character(kind = c_char) :: jobz, range, uplo
 integer(kind = c_int) :: il, info, iu, ldz, m, n
 real(kind = c_double) :: abstol, vl, vu
 integer(kind = c_int) :: ifail( * ), iwork( * )
 real(kind = c_double) :: rwork( * ), w( * )
 complex(kind = c_double_complex) :: ap( * ), work( * ), z( ldz, * )

 call zhpevx(JOBZ, RANGE, UPLO, N, AP, VL, VU, IL, IU, &
             abstol, m, w, z, ldz, work, rwork, iwork, &
             ifail, info)

end subroutine

A subroutine defined like this can be represented by the following C++
prototype: 

extern "C" void zhpevx(
	char * JOBZ, char * RANGE, char * UPLO, int * N,
	std::complex<double> * AP, double * VL, double * VU, int * IL,
	int * IU, double * abstol, int * m, double * w,
	std::complex<double> * z, int * ldz, std::complex<double> *
	work, double * rwork, int * iwork, int * ifail, int * info
);

This is the approach described in WRE 6.6.1 Fortran character strings
near the code block with the definition of subroutine c_dgemm.

-- 
Best regards,
Ivan

[*]
https://gcc.gnu.org/onlinedocs/gfortran/Argument-passing-conventions.html



More information about the R-package-devel mailing list