[MLton-user] nlffi struct or union arguments

Matthew Fluet fluet@cs.cornell.edu
Tue, 13 Jun 2006 07:47:36 -0400 (EDT)


> MLton's mlnlffigen does not currently support C functions with struct or 
> union arguments.

Correct.  The difficulty is that different platforms have different 
conventions for passing struct/union arguments and not all of these can 
(easily) be desugared into MLton's FFI.

> I'm making the assumption that this means it _will_ support pointers to 
> structs or unions.

Correct.

> It's been so long since I used C, I can't remember that you could actually do 
> something like :
>
> struct {
> ...
> } foo;
>
> func(foo);
> 
> instead of
>
> func (&foo);

Both function calls are allowed in C, though they have different 
semantics.  The first will pass a copy of the struct foo, so any 
assignments to the struct fields in func won't be seen by the caller.  The 
second will pass a pointer to the struct foo, so assignments will be seen 
by the caller.

> So annoying function calls which used structs/unions directly could simply be 
> recoded with pointers... ?

Yes, but the penalty is introducing a wrapper C function.  For example:

typedef struct foo { ... };

void func(struct foo);

void wrap_func(struct foo *p) {
   func(*p);
}