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

David C. Norris David_Norris at brown.edu
Fri Sep 14 05:22:53 MEST 2007


Is it possible to foreign export a void function having only one output 
parameter?

My understanding is that one exports a void function by returning from 
Clean a tuple, the components of which become output parameters.  Clean 
appears to require that tuples have two or more components.  Does this 
prevent foreign export of a function with a signature like

void f(int, int, int *)?

Must one attach a bogus second component to the returned tuple, as 
follows, thereby exporting a C signature with an extra, unused output 
parameter?

----
implementation module f

import StdEnv

foreign export f

f :: !Int !Int -> (!Int, !Int)
f a b = (sum [a..b], 0)

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

call_fviaC :: !Int !Int -> Int
call_fviaC a b = code {
    ccall fviaC "GII:I"
}

Start = call_fviaC 1 10
---
/* f.c */
#include "Clean.h"
extern void f(int, int, int *, int *);

int fviaC(int a, int b)
{
    int c, bogus;

    f(a, b, &c, &bogus);
    return c;
}
---
Regards,
David



More information about the clean-list mailing list