[clean-list] Foreign export of void function with a single output parameter?

John van Groningen johnvg at cs.ru.nl
Fri Sep 14 13:27:23 MEST 2007


David Norris wrote:
>Is it possible to foreign export a void function having only one output parameter?

If a Clean function is foreign exported that yields only one result
(not a tuple), the c function should return the result as the result of
the function. It is not possible to return this result using a c function
with void as result type and an extra pointer parameter for the address
where the result should be stored.

>My understanding is that one exports a void function by returning from Clean a tuple, the components of which become output parameters.

Because c functions can yield only one result, Clean's c interface
uses a c function with void result and output parameters in a function
yields more than one result (a tuple in Clean). If there
is only one result, this is not necessary.

> Clean appears to require that tuples have two or more components.

That is correct.

>  Does this prevent foreign export of a function with a signature like
>
>void f(int, int, int *)?

Yes, instead use:

int f (int,int)

However, if a c function is called from clean, it is possible to call
the function f with type

void f (int,int,int *)

using

call_f :: !Int !Int -> Int
call_f a b = code {
    ccall f "GII:VI"
}

It also possible to yield the first result of a tuple as the result of
a c function, and the rest of the tuple using pointer arguments. For
example:

int f (int,int,int *)

can be called using:

call_f :: !Int !Int -> (!Int,!Int)
call_f a b = code {
    ccall f "GII:II"
}

Kind regards,

John van Groningen


More information about the clean-list mailing list