[Haskell-cafe] FFI ccall struct return by value on the stack?

Merijn Verstraaten merijn at inconsistent.nl
Tue Jun 16 14:55:05 UTC 2020


I don't really have an opinion on the two alternatives, they both seem fine to me. I just wanted to chime in on the following:

> On 16 Jun 2020, at 16:44, ☂Josh Chia (謝任中) <joshchia at gmail.com> wrote:
> Is there just no way to return a struct by value on the stack?

There is indeed no way to do so, and this is a fundamental limitation not of Haskell, but of the ABI on your platform. To call unknown code, you need to know, well, how to call it.

On most platforms the only portable/reliable specification for this is the C ABI (which is why every FFIs to/via C), however this ABI just doesn't defined how passing structs as arguments or returning them as results should work (at least not on any platform I'm aware of).

This means that *no* language can portably pass structs to/from code via the C ABI (including C code compiled by, say, different compilers!).

Kind regards,
Merijn


More information about the Haskell-Cafe mailing list