[Rd] Splus/R typedef for C equivalent of S "integer"

Bill Dunlap bill at insightful.com
Wed Jun 4 22:23:26 CEST 2008


On Wed, 4 Jun 2008, Prof Brian Ripley wrote:

> Bill,
>
> R's R.h already has
>
> typedef double Sfloat;
> typedef int Sint;
> #define SINT_MAX INT_MAX
> #define SINT_MIN INT_MIN

Whoops, I forgot the name and that I'd put it into
Splus's R.h (and now in someing included by it)
a while back.  Quite a few R packages use it.

I was looking through "Writing R Extensions" for mention
of such a thing and didn't find it.  Perhaps the 'int's
in the examples in Chapter 5 could be changed to 'Sint's.

A few packages (gee,lasso2,locfit,AnalyzeFMRI) used to
typedef Sint (for R and Splus), but since you already
have it in R we can go with it.

In the current development version of Splus it has an
associated #ifdef/#define so packages can avoid it if
needed:

  #ifndef HAVE_SINT_TYPEDEF
  typedef long Sint ; /* C type for S language "integer", is int in R */
  #define HAVE_SINT_TYPEDEF
  #endif

To make the packages even more portable with respect
to int/long things, we need to encourage the use of casts
when interfacing to non-S code.  E.g.,
  Sint x_zero = INTEGER(x)[0] ;
  Rprintf("First element of x is %ld\n", (long)x_zero);
will print x[0] properly in R and Splus but
  Rprintf("First element of x is %d\n", x_zero);
will not work properly in Splus.

Thanks,
  Bill

----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."



More information about the R-devel mailing list