[prev in list] [next in list] [prev in thread] [next in thread] 

List:       haskell-ffi
Subject:    Re: Template GreenCard
From:       Rafael Martinez Torres <rmartine () fdi ! ucm ! es>
Date:       2004-11-18 9:36:18
Message-ID: Pine.LNX.4.58.0411181015380.26708 () segovia ! sip ! ucm ! es
[Download RAW message or body]



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)


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic