Skip to content
Prev 42807 / 63424 Next

malloc/calloc/strdup and R's aequivalents

On 18 March 2012 at 06:16, oliver wrote:
| > R> library(inline)
| > R> 
| > R> f <- cfunction(signature(), verbose=TRUE, body='
| > +    double *p = Calloc(5, double);
| [...]
| 
| That line cleared the issue.
| Thank you for providing an example.
| 
| When reading in the documentation I was not sure,
| how to interpret "type" in setion 6.1.2.
| 
| It was meant as the name of the type, and that's, why my
| sizeof() stuff created the problem.
| 
| I tried around and then saw, that the name of the type
| is accepted, not only with typical base-types of C, but
| it also eats the names of my structs/typedefed structs.

Understandable, the manual is not toi clear there.  The easiest answer, in
such cases, is IMHO provided by other source packages.

Too bad the Google Code Search is now defunct.  But besides a recursive grep
in R's src/ directory, a simple Google search for "site:r-project.org Calloc"
also brings the solution up rightaway.

Dirk