Loading ...
Sorry, an error occurred while loading the content.
 

Val_unit as returned value from C

Expand Messages
  • Peter Halacsy
    Hi, is there any difference between the next two solution? value some_proc(value v) { CAMLparam1(v); // do sg CAMLreturn (Val_unit); } void some_proc(value v)
    Message 1 of 2 , Nov 3, 2006
      Hi,
      is there any difference between the next two solution?

      value some_proc(value v) {
      CAMLparam1(v);
      // do sg
      CAMLreturn (Val_unit);
      }

      void some_proc(value v) {
      CAMLparam1(v);
      // do sg
      CAMLreturn0
      }

      if I want to use as

      extern ocaml_proc: int -> unit = "some_proc"


      peter
    • Robert Roessler
      ... Use the CAMLreturn(Val_unit)! The two key issues are: 1) using a CAMLreturn... rather than a C/C++ return - which you seem to already have down pat. 2)
      Message 2 of 2 , Nov 3, 2006
        Peter Halacsy wrote:
        > Hi,
        > is there any difference between the next two solution?
        >
        > value some_proc(value v) {
        > CAMLparam1(v);
        > // do sg
        > CAMLreturn (Val_unit);
        > }
        >
        > void some_proc(value v) {
        > CAMLparam1(v);
        > // do sg
        > CAMLreturn0
        > }
        >
        > if I want to use as
        >
        > extern ocaml_proc: int -> unit = "some_proc"

        Use the CAMLreturn(Val_unit)! The two key issues are:

        1) using a CAMLreturn... rather than a C/C++ return - which you seem
        to already have down pat.

        2) CAMLreturn0 cleans up the local roots and then does a C/C++ "void"
        return, i.e., NO value... which is definitely not the same as "unit".

        Make sure you digest Chapter 18 ("Interfacing C with Objective Caml")
        of the manual.

        Robert Roessler
        robertr@...
        http://www.rftp.com
      Your message has been successfully submitted and would be delivered to recipients shortly.