Re: Template GreenCard

Rafael Martinez Torres <[email protected]> Thu, 18 Nov 2004 10:36:18 +0100 (CET)
Newsgroups gmane.comp.lang.haskell.ffi
Message-ID <[email protected]>

On Wed, 17 Nov 2004, Rafael Martinez Torres wrote:

>
> I have no problems to interface such a function in C with the next
> prototype:
>
> int foo(int a, int b);
>
> Problemas arise when dealing with variable-arguments prototypes like :
>
> int foo( int a, ...);
>
> How to solve it ?
>

This what I have found : it may be usefull for ffi readers:

This is not very precise, but usually you may find sligth variations on a
variadic function such as:

int foo(int a, char b,int count,...);
int fooA(int a, char b, (void *) args);
int fooV(int a, char b, va_list args);

Each one implements an specific calling convention we should follow.

For Haskell wrappers, should not be difficult tryin to wrap the second:

foo :: CInt -> CChar -> [Arg] -> IO(CInt)
foo i c args = do
	ptr <- allocArgs args -- Following the particular calling convention
        b <- fooA i c ptr --Note the fooA
	return b

fooA :: CInt -> CChar -> Ptr a -> IO(CInt)