caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Interfacing with C question...
@ 2007-01-24 17:23 David Allsopp
  2007-01-25  6:27 ` [Caml-list] " Remi Vanicat
  2007-01-25 16:26 ` Hendrik Tews
  0 siblings, 2 replies; 5+ messages in thread
From: David Allsopp @ 2007-01-24 17:23 UTC (permalink / raw)
  To: OCaml List

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-01-26  0:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-01-24 17:23 Interfacing with C question David Allsopp
2007-01-25  6:27 ` [Caml-list] " Remi Vanicat
2007-01-25 16:26 ` Hendrik Tews
2007-01-25 18:29   ` skaller
2007-01-26  0:16     ` Robert Roessler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).