[Haskell-cafe] Re: Can my type be allowed as return type in FFI?

Richard O'Keefe ok at cs.otago.ac.nz
Wed Dec 10 23:58:23 EST 2008


On 11 Dec 2008, at 5:17 am, Mauricio wrote:
> This would  solve half my problem.  Can I always  trust that? I've
> been told before  that everytime a C function  returns a struct it
> is actually  returning a pointer, but  I wasn't able  to find that
> written  in stone

That's because it isn't true.
In fact one of the classical ways for a C function to
return a struct is to be *GIVEN* a pointer, e.g.,

	struct Foo f(......) {
	    ...
	    return x;
	}
=>
	void f(struct Foo *_hidden, ......) {
	    ...
	    *_hidden = x;
	    return;
	}

and obviously a C compiler is entitled to return a small struct
in registers if it feels like it.



More information about the Haskell-Cafe mailing list