From simon.urbanek at r-project.org  Tue Aug 18 14:08:42 2009
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Tue, 18 Aug 2009 08:08:42 -0400
Subject: [Rd] Calling C functions with value parameters
In-Reply-To: <xmrws52plho.fsf@mralx1.rsma.frb.gov>
References: <xmrws52plho.fsf@mralx1.rsma.frb.gov>
Message-ID: <5C1C84AD-D53C-4000-B94E-BAA4A91DA438@r-project.org>

Jeff,

On Aug 17, 2009, at 10:23 , Jeffrey J. Hallman wrote:

> One hassle I could do without is the necessity of writing C wrapper  
> functions
> like this:
>
> void fameInit(int *status){
>  cfmini(status);
>  return;
> }
>
> when I want to call a library function (cfmini, in this case) that  
> takes an
> int argument.  The .C interface only lets me pass a pointer to an  
> int, rather
> than the int itself.
>
> Is there any chanch that .C could be enhanced to allow passing  
> arguments by value to the compiled code?

IMHO close to 0, because there is not such a thing as "scalar int" in  
R. All objects in R are arrays (in C speak), so in all three:
foo(integer(0)), foo(1L), foo(1:10)
the argument is of the same type: integer vector (analogously C type  
int[]). In fact .C should preferably not be used for wrappers like the  
one you suggested, because it's more prone to errors and much less  
flexible than .Call which gives you all you want including the control  
over duplication and the length of the supplied arguments.

(There are some packages that can generate wrappers from function  
arguments or header files - maybe the authors can comments on that if  
they wish).

Cheers,
Simon



[Rd] Calling C functions with value parameters
Simon Urbanek