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] Exceptions and C
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Mitchell N Charity <mcharity@v...>
Subject: [Caml-list] Exceptions and C
I rather expected this to raise an exception...

$ cat 
let plus_f  x y = x +. y;;
Callback.register "plus_f" plus_f;;

$ cat test2.c
#include <caml/mlvalues.h>
#include <caml/memory.h>
#include <caml/callback.h>
#include <stdio.h>

int main (int argc, char **argv) {
  char * args[2] = { "fake_name", NULL };

    value the_args[3];
    the_args[0] = copy_double(32.1);
    the_args[1] = copy_string("go boom"); /** incorrect type **/
    f = *(caml_named_value("plus_f"));
    res = callbackN_exn(f,2,the_args);
    if(Is_exception_result(res)) {
      fprintf(stderr,"OCaml exception raised.\n");
    fprintf(stderr,"No exception.\n");

$ gcc -c test2.c -I/usr/local/lib/ocaml
$ ocamlopt test2.o
$ ./a.out 
No exception.

But it doesn't.

Any thoughts?

I gather run-time type checking is not occurring.  Can I at least
count on avoiding a segfault, or is behavior completely undefined if
callback arguments are incorrectly typed?

Mitchell Charity
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: