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
caml_alloc + 64 bits - caml_alloc.h
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2009-01-13 (09:37)
From: malc <av1474@c...>
Subject: Re: [Caml-list] caml_alloc + 64 bits - caml_alloc.h
On Tue, 13 Jan 2009, Daniel de Rauglaudre wrote:

> Hi everybody,
> Possibly useful information. Is it already known?
> When using calls to "caml_alloc" in a 64 bits architecture without
> having included "caml/alloc.h", it raises "Segmentation fault" at
> execution time.
> Notice that I got no warning at compilation time for using caml_alloc
> without a definition stub.
> In 32 bits architecture, I never had any problem with that.

caml_alloc returns value which is typedefed to intnat which in turn
is long which is 64bit on LP64 architectures (for all practical
intents and purposes anything that is not Win64), when prototype
for caml_alloc is missing it is assumed to be `int caml_alloc();'
assigning the return value of this call to value will sign extend
it with devastating results (upper 32bit lost forever)

> Morality:
>   Don't forget to #include "caml/alloc.h" in your C programs
>   if you alloc OCaml things!

Moraility is to follow relevant standard actually..

P.S. This whole value->intnat->long makes me wonder how OCaml is
      ever supposed to work on LLP64...