On Mon, Oct 24, 2011 at 6:04 AM, Evarist Planet <evarist.pla...@irbbarcelona.org> wrote: > Dear mailing list, > > I have a C function that gives me a wrong result when I run it under Windows > 7.
The fact that you extract pointers to the contents of fchr and sign before coercing them to REALSXP is deeply suspicious to me, though I admit I don't see how it causes the problem, since you don't use the new versions, you don't overwrite them, and the old versions should still be protected as arguments to the function. > SEXP getEs(SEXP fchr, SEXP sign) > { > int i, nfchr, nsign; > double *rfchr = REAL(fchr), *res; > int *rsign = INTEGER(sign); > > PROTECT(fchr = coerceVector(fchr, REALSXP)); > PROTECT(sign = coerceVector(sign, REALSXP)); > > nfchr = length(fchr); > nsign = length(sign); > > SEXP es; > PROTECT(es = allocVector(REALSXP, nfchr)); > res = REAL(es); > > double nr = getNr(rfchr, rsign, nsign); > > SEXP phit; > PROTECT(phit = allocVector(REALSXP, nfchr)); > double *rphit; > rphit = REAL(phit); > for(i = 0; i < nfchr; i++) rphit[i] = 0.0; > getPhit(rfchr, rsign, nsign, nr, rphit); > cumsum(rphit, nfchr); > > SEXP pmiss; > PROTECT(pmiss = allocVector(REALSXP, nfchr)); > double *rpmiss; > rpmiss = REAL(pmiss); > for(i = 0; i < nfchr; i++) rpmiss[i] = 0.0; > getPmiss(rsign, nfchr, nsign, rpmiss); > cumsum(rpmiss, nfchr); > > for (i = 0; i < nfchr; ++i) { > res[i] = rphit[i] - rpmiss[i]; > } > > UNPROTECT(5); > return es; > } > > Could you please help me to find out what I am doing wrong? > > Many thanks in advance, > > -- > Evarist Planet > Research officer, Bioinformatics and Biostatistics unit > IRB Barcelona > Tel (+34) 93 402 0553 > Fax (+34) 93 402 0257 > > evarist.pla...@irbbarcelona.org > http://www.irbbarcelona.org/bioinformatics > > [[alternative HTML version deleted]] > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > -- Thomas Lumley Professor of Biostatistics University of Auckland ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel