Re: [Rd] Interfacing R and C++

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Mon 09 Jan 2006 - 20:20:23 GMT

The wrapper function must be in extern "C" {} since you want to give it a C name (and not a mangled C++ one). These days, the headers probably do not need to be, but in theory if they are C headers they should be in any C++ code.

I think R-exts is quite clear on this:

   To use with @R{}, the only thing we have to do is writing a wrapper

   function and ensuring that the function is enclosed in
                              ^^^^^^^^^^^^^^^^^^^^^^^^



On Mon, 9 Jan 2006, Sean Davis wrote:

> I have a single c++ file that contains a class and a "wrapper" function that
> has C-like syntax for interacting with the Class. Basically, this wrapper
> function just makes an instance of the class and then organizes the data for
> return to R.
>
> #include <math.h>
>
> void myFunc(double *data, int *n, double *prm, double* intervals, int* max,
> double *plot) {
> ...
> }
>
> myClass::myclass(...) {
> ...
> }
>
> My question is simple: what goes inside the extern "C" {} block. Should it
> include only the #includes, those and the "wrapper" function, or the entire
> .cc file? The answer wasn't clear to me from the Writing R extensions
> manual (probably due to my c++ ignorance--using someone else's code).
>
>> sessionInfo()
> R version 2.2.0, 2005-08-11, powerpc-apple-darwin7.9.0
>
> attached base packages:
> [1] "methods" "stats" "graphics" "grDevices" "utils" "datasets"
> [7] "base"
>
> I'm trying to use the .C interface and getting segmentation faults--probably
> a bug in the code, but just wanted to make sure that it wasn't a simple
> issue with the extern block.
>
> Thanks,
> Sean
>
> ______________________________________________
> R-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Tue Jan 10 07:30:24 2006

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:36 GMT