caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Unsigned int ?!
@ 2000-06-16  9:57 Luc MAZARDO
  2000-06-19 15:51 ` Xavier Leroy
  2000-06-23 16:05 ` thierry BRAVIER
  0 siblings, 2 replies; 3+ messages in thread
From: Luc MAZARDO @ 2000-06-16  9:57 UTC (permalink / raw)
  To: caml-list


I would like to get the "caml unsigned int value" of an "unsigned int C
value". Is there a way to do this ??

I do the following, and it fails ...


---toto_stub.c---
value toto(void)
{
  return Val_int(get()); 
}
------------

---toto.mli---
val toto : unit -> int ;;
------------

---toto.ml---
external toto : unit -> int = "toto";;
-------------

---test.c---
<<some stuff>>

printf("%d\n", toto()); /* unsigned int: --> 3 */

<<some stuff>>
-----------


---test.ml---
let t = toto () ;;
val t : int = -924646501 /* uh ?? */
-------------


-- 
Luc Mazardo
http://OCamlSDL.sourceforge.net
Gnu Emacs:flame.el Don't you realise that Michael Jackson is a cool
dude?



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unsigned int ?!
  2000-06-16  9:57 Unsigned int ?! Luc MAZARDO
@ 2000-06-19 15:51 ` Xavier Leroy
  2000-06-23 16:05 ` thierry BRAVIER
  1 sibling, 0 replies; 3+ messages in thread
From: Xavier Leroy @ 2000-06-19 15:51 UTC (permalink / raw)
  To: Luc MAZARDO, caml-list

> I would like to get the "caml unsigned int value" of an "unsigned int C
> value". Is there a way to do this ??
> I do the following, and it fails ...

I tried to reproduce the problem from your (incomplete) code snippet,
and everything worked fine.  If you have a complete (self-contained)
program that reproduces the problem, please send it to
caml-bugs@inria.fr.

As for the unsigned vs. signed issue, it's just two ways to view the
same bit patterns: the most significant bit of the unsigned int becomes
the sign bit of the signed int.  So, for "small enough" unsigned ints,
you will see them as the corresponding Caml int; large unsigned ints
wrap around.

- Xavier Leroy



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Unsigned int ?!
  2000-06-16  9:57 Unsigned int ?! Luc MAZARDO
  2000-06-19 15:51 ` Xavier Leroy
@ 2000-06-23 16:05 ` thierry BRAVIER
  1 sibling, 0 replies; 3+ messages in thread
From: thierry BRAVIER @ 2000-06-23 16:05 UTC (permalink / raw)
  To: caml-list

Luc MAZARDO a écrit:

> I would like to get the "caml unsigned int value" of an "unsigned int C
> value". Is there a way to do this ??
>
> I do the following, and it fails ...
>
> ---toto_stub.c---
> value toto(void)
> {
>   return Val_int(get());
> }
> ------------

I think you should add:
value toto_external (value unit) { /* unit is  necessary for this external
function */
   return toto ();
}

> ---toto.mli---
> val toto : unit -> int ;;
> ------------
>
> ---toto.ml---
> external toto : unit -> int = "toto";;

Here you would rather write:
external toto : unit -> int = "toto_external";;

Anyway whether your version fails, returns a wrong result or anything else
cannot be predicted
since it is related to the function call protocol of your machine.

Or maybe I am wrong since I did not try this on my computer  :-)

Hope this helps.

Thierry Bravier



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2000-06-26 10:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-16  9:57 Unsigned int ?! Luc MAZARDO
2000-06-19 15:51 ` Xavier Leroy
2000-06-23 16:05 ` thierry BRAVIER

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).