Skip to content
Prev 6430 / 12125 Next

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

On 12/19/20 12:57 AM, Pierre Lafaye de Micheaux wrote:
Dear Pierre,


I meant rather something like this (in plain C, there is no need to use 
C++ for this):


---------------


#include <stddef.h>??????? /* for size_t (FC_LEN_T) */

#include <Rconfig.h>?????? /* for FC_LEN_T, FCONE */
#include <R_ext/BLAS.h>??? /* for FCONE */
#include <R_ext/RS.h>????? /* for F77_... */
#include <R_ext/Complex.h> /* for Rcomplex */

void F77_NAME(zhpevx)(char *jobz, char *range, char *uplo,
 ????????????????????? const int *n, Rcomplex *ap, const double *vl,
 ????????????????????? const double *vu, const int *il, const int *iu,
 ????????????????????? const double *abstol, int *m, double *w,
 ????????????????????? Rcomplex *z, const int *ldz, Rcomplex *work, 
double *rwork,
 ????????????????????? int *iwork, int *ifail, int *info,
#ifdef FC_LEN_T
 ????????????????????? FC_LEN_T jobz_len, FC_LEN_T range_len, FC_LEN_T 
uplo_len
#endif
 ????????????????????? );

void zhpevxC(char **jobz, char **range, char **uplo, int *n, Rcomplex *ap,
 ???????????? double *vl, double *vu, int *il, int *iu, double *abstol, 
int *m,
 ???????????? double *w, Rcomplex *z, int *ldz, Rcomplex *work, double 
*rwork,
 ???????????? int *iwork, int *ifail, int *info) {

 ??? F77_CALL(zhpevx)(*jobz, *range, *uplo, n, ap, vl, vu, il, iu, 
abstol, m, w,
 ???????????????????? z, ldz, work, rwork, iwork, ifail, info FCONE 
FCONE FCONE);
}

-----------------


with gfortran 8.3, you still get the warnings due to size_t vs "long 
int", and due to the complex type (the compiler complains between the 
difference between _Complex and Rcomplex). With newer gfortran (9.3) 
there are no warnings.
When you are copying the memory from Rcomplex array to _Complex array, 
you are still assuming the memory layout is compatible. But in addition, 
you have more code, use more memory, spend execution time copying 
(that's what I meant by runtime tricks). In case the memory layouts were 
actually different, there would still be a problem and it would be 
harder to find, because you have silenced the warning. I think it is 
strictly better to use a version that is not hiding this potential 
problem, along the lines I've written above. Also there should be no 
need to copy the incoming characters as in the original version. And, 
one can just write "n" instead of "&n[0]".


A portable version that would work for older and newer compilers (and 
other compilers) could only be created using iso_c_binding.


If you just wanted to silence the warnings (but, really, I think that 
would not be a good thing to do), you in principle still do that by 
redefining FC_LEN_T and Rcomplex, without any runtime overhead, but that 
would be hiding potential problems as well.


Best
Tomas