Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between ccall and capi FFI calling conventions

Tags:

haskell

ffi

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?

like image 986
crockeea Avatar asked Jun 07 '16 19:06

crockeea


1 Answers

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.

like image 197
melpomene Avatar answered Oct 18 '22 14:10

melpomene