Difference between ccall and capi FFI agreements

I found that there are two calling conventions using GHC FFI : ccall and capi . The documents do not have much information about these two agreements. What is the difference between them and when should I use them? Is one faster than the other?

+5
source share
1 answer

ccall is the usual way. It works by directly linking to a character defined in a library (usually written in C).

capi is a ghc extension that runs at source level C. That's why it can access things that don't exist at the ABI level, like macros. (I don't know how this is implemented, but I would suggest that it generates a small shell of the C function, which it then compiles with the C compiler behind the scenes.)

I would use ccall where possible. It is part of the locale and looks less β€œmagical” overall.

+6
source

All Articles