Template GreenCard

Rafael Martinez Torres rmartine at fdi.ucm.es
Thu Nov 18 04:36:18 EST 2004



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)




More information about the FFI mailing list