[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] return a pair of ints from a C function?
From: |
Ivan Raikov |
Subject: |
Re: [Chicken-users] return a pair of ints from a C function? |
Date: |
Thu, 31 Jul 2008 16:46:45 +0900 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) |
To return fixnums, you can do:
C_word g2d_glyphs_baseline(struct G2dGlyphs* glyphs)
{
C_word* a = C_alloc(C_SIZEOF_PAIR);
C_return(C_pair (&a, C_fix(10), C_fix(256)));
}
To return a pair of flonums (which is what you are doing with
C_int_to_num), you need to allocate memory for the numbers thusly:
C_word g2d_glyphs_baseline(struct G2dGlyphs* glyphs)
{
C_word* lst = C_alloc(C_SIZEOF_PAIR);
C_word *a, *b;
a = C_alloc (C_SIZEOF_FLONUM);
b = C_alloc (C_SIZEOF_FLONUM);
C_return (C_pair (&lst, C_int_to_num (&a, 10), C_int_to_num (&b, 256)));
}
"Shawn Rutledge" <address@hidden> writes:
> OK dumb question time again: I'm trying to return a pair of fixnums
> from a C function.
>
> C_word g2d_glyphs_baseline(struct G2dGlyphs* glyphs)
> {
> C_word* a = C_alloc(C_SIZEOF_PAIR + 8);
> C_return(C_pair (&a, C_int_to_num(&a, 10), C_int_to_num(&a, 256)));
> }
>
> or maybe
>
> C_word g2d_glyphs_baseline(struct G2dGlyphs* glyphs)
> {
> C_word* c_ret = C_alloc(C_SIZEOF_PAIR);
> C_word* a = c_ret;
> C_int_to_num(&a, 10);
> C_int_to_num(&a, 256);
> C_return(*c_ret);
> }