crockeea
crockeea

Reputation: 21811

Difference between ccall and capi FFI calling conventions

I discovered that there are two calling conventions using GHC's FFI: ccall and capi. The docs don't have much information about the two conventions. What is the difference between them, and when should I use each one? Is one faster than the other?

Upvotes: 6

Views: 748

Answers (1)

melpomene
melpomene

Reputation: 85837

ccall is the normal way. It works by directly linking against a symbol defined in a (usually written in C) library.

capi is a ghc extension that works on the C source level. That's why it can access things that don't exist at the ABI level, such as macros. (I don't know how it's implemented, but I would guess it generates a small C function wrapper, which it then compiles with a C compiler behind the scenes.)

I would use ccall where possible. It's part of the language standard and looks less "magical" in general.

Upvotes: 7

Related Questions