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
Interfacing with C question...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-01-24 (17:23)
From: David Allsopp <dra-news@m...>
Subject: Interfacing with C question...
Sorry if this an RADBOTFM case. Rule 2 in Chapter 18 of the manual states
that all local variables of type value must be declared using CAMLlocal
macros. However, later on when demonstrating caml_callback we get the

value* format_result_closure = caml_named_value("format_result");
return strdup(String_val(caml_callback(*format_result_closure, Val_int(n))))

(I've "simplified" the opening lines for clarity here - naturally it should
be static and once only!).

Two questions arise:

1. Presumably it's OK to cache values returned by caml_named_value without
declaring them in a CAMLlocal "call" or by using register_global_root?
2. The result of caml_callback is passed straight to String_val. Therefore,
if I expand the line to:

value result = caml_callback(*format_result_closure, Val_int(n)));
return strdup(String_val(result));

then does that work ok without using CAMLlocal1(result);