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 PAA14372; Wed, 14 Nov 2001 15:55:51 +0100 (MET) 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 PAA14286 for ; Wed, 14 Nov 2001 15:55:50 +0100 (MET) Received: from mail.mimuw.edu.pl (paf87.warszawa.sdi.tpnet.pl [217.96.225.87]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id fAEEtj526698 for ; Wed, 14 Nov 2001 15:55:46 +0100 (MET) Received: (from news@localhost) by mail.mimuw.edu.pl (PLD/8.9.3) id PAA22528 for caml-list@inria.fr; Wed, 14 Nov 2001 15:56:26 +0100 X-Authentication-Warning: qrnik.zagroda: news set sender to Marcin 'Qrczak' Kowalczyk using -f From: "Marcin 'Qrczak' Kowalczyk" Subject: Re: [Caml-list] camlidl and pointer to function Date: Wed, 14 Nov 2001 14:56:23 +0000 (UTC) Organization: Klub Nieszkodliwych =?iso-8859-2?Q?Manjak=F3w?= Message-ID: References: <3BF23EE4.BB444C5C@crf.canon.fr> <9stni6$hh6$1@qrnik.zagroda> X-Trace: qrnik.zagroda 1005749783 21284 192.168.0.1 (14 Nov 2001 14:56:23 GMT) X-Complaints-To: abuse@localhost NNTP-Posting-Date: Wed, 14 Nov 2001 14:56:23 +0000 (UTC) User-Agent: slrn/0.9.7.2 (Linux) To: caml-list@inria.fr Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 14 Nov 2001 15:16:15 +0300, Dmitry Bely pisze: > The problem is that C library is binary-only (Intel image processing > library), and CallBack type is exactly > > typedef int (*CallBack)(int); Converting a function closure to a C function pointer can't be done portably, but it can be done with lots of ugly magic. Glasgow Haskell does this (by generating a piece of assembler on the heap) and it's convenient to use from the level of Haskell. Such functions need to be explicitly freed of course. GNU C does this for local functions, but only "downwards". If the function pointer doesn't need to live longer than the function which installs the callback, the GNU C extension can be used. It generates the piece of assembler on the stack. To use it - just define a function inside a function and take its address. It would be nice if OCaml provided this functionality because not all C libraries provide the extra argument for simulating closures. Unfortunately it can't be implemented nicely. I've once seen a C library which tries to provide it for several platforms but I forgot its name. -- __("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/ \__/ ^^ QRCZAK ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr