summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorIan Lynagh <igloo@earth.li>2012-02-26 01:46:06 +0000
committerIan Lynagh <igloo@earth.li>2012-02-26 13:04:44 +0000
commitae04bd43a2640e17a9035f170d76dae356082f88 (patch)
treef17b95d0840f4ee66ee622c03da1a96058ade347 /docs
parent9065bdbf5299097263c35f6e389b018806f6753e (diff)
downloadhaskell-ae04bd43a2640e17a9035f170d76dae356082f88.tar.gz
Implement "value" imports with the CAPI
This allows us to import values (i.e. non-functions) with the CAPI. This means we can access values even if (on some or all platforms) they are simple #defines.
Diffstat (limited to 'docs')
-rw-r--r--docs/users_guide/ffi-chap.xml22
1 files changed, 20 insertions, 2 deletions
diff --git a/docs/users_guide/ffi-chap.xml b/docs/users_guide/ffi-chap.xml
index b5ae0e06e4..34c2b35a3a 100644
--- a/docs/users_guide/ffi-chap.xml
+++ b/docs/users_guide/ffi-chap.xml
@@ -169,8 +169,7 @@ foreign import ccall interruptible
declarations, e.g.
<programlisting>
-foreign import capi
- "header.h f" :: CInt -> IO CInt
+foreign import capi "header.h f" f :: CInt -> IO CInt
</programlisting>
Rather than generating code to call <literal>f</literal>
@@ -182,6 +181,25 @@ foreign import capi
</para>
<para>
+ When using <literal>capi</literal>, it is also possible to
+ import values, rather than functions. For example,
+
+<programlisting>
+foreign import capi "pi.h pi" c_pi :: CDouble
+</programlisting>
+
+ will work regardless of whether <literal>pi</literal> is
+ defined as
+<programlisting>
+const double pi = 3.14;
+</programlisting>
+ or with
+<programlisting>
+#define pi 3.14
+</programlisting>
+ </para>
+
+ <para>
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