From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA05504; Tue, 23 Jul 2002 10:39:19 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id KAA05659 for ; Tue, 23 Jul 2002 10:39:18 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id g6N8dGT15546; Tue, 23 Jul 2002 10:39:16 +0200 (MET DST) Received: (from xleroy@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA05207; Tue, 23 Jul 2002 10:39:16 +0200 (MET DST) Date: Tue, 23 Jul 2002 10:39:16 +0200 From: Xavier Leroy To: Michael Tucker Cc: "Caml-List@Inria.Fr" Subject: Re: [Caml-list] CamlIDL and function pointers Message-ID: <20020723103916.B30947@pauillac.inria.fr> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from mtucker@eecs.harvard.edu on Mon, Jul 22, 2002 at 05:13:41PM -0400 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > How would one annotate the following C struct for camlidl: > > typedef struct funp { > int i; > void (*funp_fun) (); > } funp_t; > > Is it possible? Looking at the specs I don't see how one can have a > field that is a pointer to a function. Any ideas, or pointers (no pun > intended) to examples? CamlIDL, like the DCE and Microsoft IDL from which it derives, doesn't support exchanging function pointers between C and Caml. Your best bet is to declare funp_t as an abstract type in the IDL file: typedef [abstract] struct funp * funp_t; and export C functions that do what you need to do on this funp_t type, e.g. void invoke(funp_t arg); where "invoke" is defined directly in C somewhere else: void invoke(funp_t arg) { arg->funp_fun(arg->i); } Of course, you won't be able to, say, construct a funp_t where the function part is actually a Caml function. If you need that kind of callback mechanism, you'll have to write some of the stub code by hand, using Caml's callback functions. Alternatively, if you can re-shape your struct funp till it looks like a COM interface, you could then use the CamlIDL "interface" declaration and get Caml->C and C->Caml calls. Hope this helps, - Xavier Leroy ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners