Le Sunday 07 Aug 2011 à 22:48:08 (-0500), Romain Beauxis a écrit :
> 2011/8/7 Erik de Castro Lopo <[email protected]>:
> > Hi all,
>
> Hi,
>
> > I'm writing a C stub function to allow the calling of a C library
> > function from ocaml. The return from the stub is a tuple and I'm
> > doing this:
> >
> > /* Package up the result as a tuple. */
> > v_response = caml_alloc_tuple (3) ;
> >
> > Store_field (v_response, 0, Val_int (width)) ;
> > Store_field (v_response, 1, Val_int (height)) ;
> > Store_field (v_response, 2, caml_copy_string (code)) ;
> >
> > CAMLreturn (v_response) ;
> >
> > The above works now, but didn't work when I was using
> > caml_copy_nativeint() instead of Val_int() and I'd like to know
> > why. I found it especially confusing because caml_copy_string()
> > worked and was obvioulsy the right thing to do.
>
> Reading very briefly the headers. is seems to me that intnat = value =
> long. Could it be that on the arch you're using sizeof(int) <
> sizeof(long) ?
>
> Romain
Given that Val_int is Val_long (in mlvalues.h):
#define Val_int(x) Val_long(x)
it's not an issue with this piece of code.
But depending on what "doesn't work" means and on the declarations of
width and height, then sizeof(int) < sizeof(long) may explain the issue.
--
Guillaume Yziquel
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs