On 12-07-26 4:22 PM, Spencer Graves wrote:> Hello, All:
>
>
> What references exist on how to link to C?
>
>
> I'm familiar with sections 5.2 and 5.6 of the "Writing R
> Extension" manual plus chapter 6 of Venables and Ripley (2000) S
> Programming (Springer). From these, I get the following:
>
>
> R storage mode C type
> logical int *
> integer int *
> double double *
> complex Rcomplex *
> character char **
> raw unsigned char *
> list SEXP *
> R object SEXP
>
>
> "integer" and "int" are 32 bits. If I
understand correctly,
> "short" has only 16 bits = 2 bytes.
I imagine that depends on the platform and compiler.
>
>
> Should I define any "short" vector in C as a matrix with
2 rows
> of type either "raw" or "char"?
What do you want to do with it in R? If you want to use .C() and just
want it to be an opaque blob, then a raw vector is probably best. Have
one C function that figures out the size in bytes of the blob, then
allocate a raw vector of that size, and call a different function to
fill it in (or the same function with different arguments...). If you
actually want to work with the short values, then you'll need to convert
them to a type that R understands, most likely int (but double would
work too).
If you want to use the .Call interface, there are some other choices,
e.g. external pointers.
Duncan Murdoch
>
>
> Thanks,
> Spencer
>
>
> p.s. I need this to link to lossless JPEG code obtained from
> "ftp.cs.cornell.edu/pub/multimed/ljpg.tar.Z"
>
>