For the FFI to be of any practical use, the properties and sizes of the various types that can be communicated between the Haskell world and the outside, needs to be precisely defined. We do this by presenting a mapping to C, as it is commonly used and most other languages define a mapping to it. Table Mapping of Haskell types to C typess defines the mapping between Haskell and C types.
Some remarks:
HsFFI.h that includes target platform specific definitions
for the above types and values.Hs{Int,Word}{8,16,32,64} have
a 1-1 mapping to ISO C 99's {,u}int{8,16,32,64}_t. For systems
that doesn't support this revision of ISO C, a best-fit mapping
onto the supported C types is provided.Hs{Int,Word}64 as a struct. In
this case the bounds HS_INT64_{MIN,MAX} and HS_WORD64_MAX
are undefined.Int has to be equal to or
wider than 30 bits. The HsInt synonym is guaranteed to map
onto a C type that satisifies Haskell's requirement for Int.Hs{Float,Double} are one of C's
floating-point types float/double/long double.float.h are provided:
HS_{FLOAT,DOUBLE}_RADIX
HS_{FLOAT,DOUBLE}_ROUNDS
HS_{FLOAT,DOUBLE}_EPSILON
HS_{FLOAT,DOUBLE}_DIG
HS_{FLOAT,DOUBLE}_MANT_DIG
HS_{FLOAT,DOUBLE}_MIN
HS_{FLOAT,DOUBLE}_MIN_EXP
HS_{FLOAT,DOUBLE}_MIN_10_EXP
HS_{FLOAT,DOUBLE}_MAX
HS_{FLOAT,DOUBLE}_MAX_EXP
HS_{FLOAT,DOUBLE}_MAX_10_EXP
#if and for array bounds.HsAddr is of the same size as void*, so
any other pointer type can be converted to and from HsAddr without any
loss of information (K&R, Appendix A6.8).Addr by the FFI, so there
is again the guarantee that HsForeignObj is the same as
void*. The separate name is meant as a reminder that there is
a finalizer attached to the object pointed to.void* is used as a generic container in most
APIs, not because they are real addresses. To make this special
case clear, a separate C type is used here. Hs and
macros starting with HS_ are reserved for the FFI.ByteArray and
MutableByteArray both map to char*.