From tlumley at u.washington.edu  Tue Jan 10 20:27:09 2006
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Tue, 10 Jan 2006 11:27:09 -0800 (PST)
Subject: [Rd] Issue with c++ .C call
In-Reply-To: <BFE96390.3659%sdavis2@mail.nih.gov>
References: <BFE96390.3659%sdavis2@mail.nih.gov>
Message-ID: <Pine.LNX.4.64.0601101115500.25401@homer24.u.washington.edu>

On Tue, 10 Jan 2006, Sean Davis wrote:
> and such.  However, the call to the function is via .C; parameters from the
> .C call are not being passed correctly to the function.  As an example, I
> have attached a GDB run of the code.  I set a breakpoint on entry to the
> function I am calling from R.  What is bothering me (and probably causing
> the segmentation faults I am seeing) is that the parameter
> prm=as.double(c(3.2,1.1)) is not 3.2,1.1 IMMEDIATELY after the call to .C.

Is this compiled with optimization? If so, you can't conclude much from 
the gdb info as the code can be executed in a different order from how 
it's written.

When I use this example

extern "C" void calcStepgram(double *data,  double *prm, double *intervals,
int *max, int *n,double *plot) {

  prm[0]=data[0];
  return;
}

if I compile with -g -02 (the default) it looks as though there are 
problems with initialization like the ones you report, but in fact the 
function works correctly.  If I compile without optimization the 
initialization looks fine.

 	-thomas



[Rd] Issue with c++ .C call
Thomas Lumley