Hi, I am writing an R package with two functions in C++. So far everything works. Now, i would like to write a third function which would use a pointer (it is a pointer to a class object) created by first function. I tried placing this pointer outside of the function definitions (i.e to make it global) but when called in the 3rd function i get > *** caught bus error *** address 0x0, cause 'invalid alignment'"
I tried Callocing it in the 1st function but to no avail. Here is a quick summary. When foo is called (through do_foo, **after** having called do_kNN_e) i get the aforementioned error. Can anyone provide some pointers (no pun intended) on this? Thanks Saptarshi ANN* book; int* foot; void foo(void){ Rprintf("many times\n"); Rprintf("%p\n",book); Rprintf("%p\n",foot); } SEXP kNN_e(SEXP data, SEXP Nrow, SEXP Ncol,SEXP K,SEXP Eps) { int nrow=asInteger(Nrow); int ncol=asInteger(Ncol); int k=asInteger(K); double eps=asReal(Eps); SEXP ans,distance; SEXP retlist; PROTECT(ans=allocMatrix(INTSXP,nrow,k)); //The 2nd argument gives the number of rows, and the last the number of cols see http://cran.r- project.org/doc/manuals/R-exts.html PROTECT(distance=allocMatrix(REALSXP,nrow,k)); ANNpointArray datapoints; ANNpoint qpoint; ANNkd_tree* kdTree; book=Calloc(1,ANN*); foot=Calloc(1,int); book=kdTree; *foot=10; ....... } extern "C" { void do_foo(void){ foo(); } SEXP do_kNN_e(SEXP data, SEXP Nrow, SEXP Ncol,SEXP k,SEXP eps) { return kNN_e(data,Nrow, Ncol, k,eps); } [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel