Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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
statements:

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);

Ta!


David