Commit 5d7fd293 authored by Ian Lynagh's avatar Ian Lynagh
Browse files

Add some docs for the CAPI extension

parent 7b24c3ff
......@@ -160,6 +160,41 @@ foreign import ccall interruptible
handle <literal>ERROR_OPERATION_ABORTED</literal>.
<sect2 id="ffi-capi">
<title>The CAPI calling convention</title>
The <literal>CAPI</literal> extension allows a calling
convention of <literal>capi</literal> to be used in foreign
declarations, e.g.
foreign import capi
"header.h f" :: CInt -> IO CInt
Rather than generating code to call <literal>f</literal>
according to the platform's ABI, we instead call
<literal>f</literal> using the C API defined in the header
<literal>header.h</literal>. Thus <literal>f</literal> can be
called even if it may be defined as a CPP
<literal>#define</literal> rather than a proper function.
In order to tell GHC the C type that a Haskell type
corresponds to when it is used with the CAPI, a
<literal>CTYPE</literal> pragma can be used on the type
definition. The header which defines the type can optionally
also be specified. The syntax looks like:
data {-# CTYPE "unistd.h" "useconds_t" #-} T = ...
newtype {-# CTYPE "useconds_t" #-} T = ...
type {-# CTYPE "unistd.h" "useconds_t" #-} T = ...
<sect1 id="ffi-ghc">
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment