[gambit-list] ___S32VECTORREF
Marc Feeley
feeley at iro.umontreal.ca
Sun Apr 5 23:07:56 EDT 2009
On 5-Apr-09, at 10:12 PM, <tom at tmilford.com> <tom at tmilford.com> wrote:
>
>
> I'm trying to use ___S32VECTORREF as ___F32VECTORREF was illustrated
> previously on this list. The rest of my code works fine, and if I
> use float homogenous arrays,
> that works.
>
>
> ___SCMOBJ shared_array;
>
> ...
>
>
> int ival = ___S32VECTORREF(shared_array, i);
>
> I've also tried
>
> int ival = ___S32VECTORREF(shared_array, ___FIX(i));
>
> Both result in:
>
> Line Location scheme-bridge.c:66: error: '___hp' undeclared (first
> use in this function)
> Line Location scheme-bridge.c:66: error: '___s32_temp' undeclared
> (first use in this function)
>
> It's not clear to me from the macro definitions in gambit.h how to
> get around this.
>
___F4VECTORREF returns a C double, i.e. it is *not* a boxed (heap
allocated) flonum.
___S32VECTORREF returns a Scheme exact integer (the C type ___SCMOBJ
defined in include/gambit.h). The thing is that if the 32 bit value
is larger than a fixnum, then a heap allocated bignum must be
created. This is why ___hp ("heap pointer") is needed in general.
You can't easily access it from arbitrary C code because there is some
non-trivial interaction with polling, heap-overflow checking, and
garbage-collecting.
In any case, from the looks of your code, this is probably not what
you wanted to do. You want a C 32 bit integer, not a Scheme 32 bit
integer.
So try:
___S32 *s32ptr = ___CAST(___S32*,___BODY_AS(shared_array,___tSUBTYPED));
___S32 ival = s32ptr[i];
Note that it is better to use ___S32 instead of "int", because "int"
is not guaranteed to be a 32 bit integer in all C environments.
Marc
More information about the Gambit-list
mailing list