Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] camlidl and pointer to function
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Marcin 'Qrczak' Kowalczyk <qrczak@k...>
Subject: Re: [Caml-list] camlidl and pointer to function
14 Nov 2001 15:16:15 +0300, Dmitry Bely <dbely@mail.ru> 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