Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Give back a Pair from C to OCaml?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-01-17 (18:41)
From: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Give back a Pair from C to OCaml?
On Thu, Jan 17, 2008 at 07:32:19PM +0100, Oliver Bandel wrote:
> For example I can use "CAMLprim value <functionname> (.....){...}"
> or I can throw out "CAMLprim" (which is, what I found in the
> OReilly-book).

It's not really a good idea to "throw out" CAMLprim.  It expands to
something useful on Windows.

> Also "value x" or "int x" are working as C-parameters
> of a function. But an OCaml-int is not the same like a
> C-int, so I would expect gcc throw out at least a warning.
> I have added "-Wall", but no warning there.

value <> int.  On normal 64 bit architectures it's defined as a long,
but basically they are not interchangable and you should always use
'value' when you mean an OCaml value.

> Possibly that's because what is mentioned in "18.2",
> that int's are "value".
> But there is no distinction between the OCaml-ints and the
> machine's C-ints in that text. Is "an unboxed integer" meant
> to be a machine's native int, 32 Bits or 64 Bits, depending on the
> machine?. Can it be given as parameter and return value as it is?

No.  A Caml int is not represented the same way as a C int.  This
doesn't matter because you should be using the macros supplied to
convert between the two representations, Val_int, Int_val, Long_val,
Unsigned_long_val etc.


Richard Jones
Red Hat