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
embedding ocaml from C++ -- PODs
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Thomas Fischbacher <tf@f...>
Subject: Re: [Caml-list] embedding ocaml from C++ -- PODs

Oliver Kania wrote:

> the OCAML documentation gives good explanation about how call OCAML 
> functions from C.
> However , what I want to do is the following. I have a C structure with 
> many fields.
> I want to be able to initialize this structure both in C and in Ocaml 
> and want access to the same instance from both languages.
> The structure could be a global object in OCAML and C. The important 
> point is that I want to have access to the very same
> data and not to any copies, which means I want to pass a reference from 
> OCAML to C or vice versa.
> More generally speaking, I would like to create objects in C and pass 
> references to these objects to the OCAML side and vice versa.
> Its all about data flow between the two sides.

Well, all accessors should conceptually be functions, not just some
weird special syntax. Perl "resolved" that issue through the
introduction of "magic", Python has something equivalent, and in Lisp,
the question des not arise in the first place, because all accessors
already are functions.

Just wrap up a couple of set_ and get_ functions and you will be fine.

best regards,
Thomas Fischbacher