From tlumley at u.washington.edu  Wed Jul  6 23:04:25 2005
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Wed, 6 Jul 2005 14:04:25 -0700 (PDT)
Subject: [Rd] R_alloc problems in R v1.11
In-Reply-To: <1120682529.42cc4221e67a7@www.courrier.umontreal.ca>
References: <1120682529.42cc4221e67a7@www.courrier.umontreal.ca>
Message-ID: <Pine.A41.4.61b.0507061359450.109146@homer05.u.washington.edu>

On Wed, 6 Jul 2005, [iso-8859-1] Marie-H?l?ne Ouellette wrote:

> Dear Dr. Ripley,

Or possibly other people on the list.

> I'm using the R v1.11 on Macintoch

Unlikely. There is no R v1.11, and R 1.1.1 (following the most common 
misspelling) wasn't available for the Mac.

>					and I seem to have a problem with the
> function R_alloc. It crashes when using the following .C function (only an
> example):
>
> ///////////////////////////////
> # include <R.h>
> void Hello(int *n)
> {
> int i,x;
> for(i=1;1< *n ; i++)

This is an infinite loop.  You probably mean i<*n as the second 
expression, or perhaps i<=*n (did you want n or n-1 repeats?)

> {
> 	Rprintf('salut!!!\n');

This is invalid C, as your compiler should have told you. You need double 
quotes.

> }
> x = (int *) R_alloc(5,sizeof(int));

x was declared as int, not int *, so again this is invalid.

> }
>
> ///////////////////////////////
>
> I call it in R with this line:
>
> .C('Hello',as.integer(5))
>
> Any idea why and how I can resolve this problem?

After fixing the C errors and in a version of R that exists (2.0.1) I get
> dyn.load("hello.so")
> .C('Hello',as.integer(5))
salut!!!
salut!!!
salut!!!
salut!!!
[[1]]
[1] 5

 	-thomas


[Rd] R_alloc problems in R v1.11
Thomas Lumley