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-list] Stop at exception
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-01-23 (15:07)
From: Xavier Leroy <xavier.leroy@i...>
Subject: [Caml-list] Re: Float and OCaml C interface
> Is it possible to call from OCaml a C function of type double
> f(double,double,double) 
> without packing and unpacking the double when using the native code
> compiler ?

Yes.  Declare it as follows:

external f : float -> float -> float -> float = "f_wrapper" "f" "float"

"f_wrapper" should be the standard C wrapper function that takes three
values, unpacks the doubles, call f, packs the result.  This wrapper
will be called by the bytecode interpreter.

"f" is just the base C function taking unboxed doubles and returning a
double.  It will be called directly by the code generated by ocamlopt.

The "float" declaration at the end instructs ocamlopt to perform (and
optimize!) the unboxing of the arguments and the boxing of the result
itself, rather than relying on "f" to do it.

> In other word, is the unboxing optimization of floats available to
> external C function ?

Yes.  The standard library uses it for most of the floating-point
functions defined in Pervasives.

- Xavier Leroy
Bug reports:  FAQ:
To unsubscribe, mail  Archives: