Foreign.C.Types (original) (raw)
Representations of C types
These types are needed to accurately represent C function prototypes, in order to access C library interfaces in Haskell. The Haskell system is not required to represent those types exactly as C does, but the following guarantees are provided concerning a Haskell type CT
representing a C type t
:
- If a C function prototype has
t
as an argument or result type, the use ofCT
in the corresponding position in a foreign declaration permits the Haskell program to access the full range of values encoded by the C type; and conversely, any Haskell value forCT
has a valid representation in C. `[sizeOf](Foreign-Storable.html#v:sizeOf)` (`[undefined](Prelude.html#t:undefined)` :: CT)
will yield the same value assizeof (t)
in C.`[alignment](Foreign-Storable.html#v:alignment)` (`[undefined](Prelude.html#t:undefined)` :: CT)
matches the alignment constraint enforced by the C implementation fort
.- The members
[peek](Foreign-Storable.html#v:peek)
and[poke](Foreign-Storable.html#v:poke)
of the[Storable](Foreign-Storable.html#t:Storable)
class map all values ofCT
to the corresponding value oft
and vice versa. - When an instance of
[Bounded](Prelude.html#t:Bounded)
is defined forCT
, the values of[minBound](Prelude.html#t:minBound)
and[maxBound](Prelude.html#t:maxBound)
coincide witht_MIN
andt_MAX
in C. - When an instance of
[Eq](Prelude.html#t:Eq)
or[Ord](Prelude.html#t:Ord)
is defined forCT
, the predicates defined by the type class implement the same relation as the corresponding predicate in C ont
. - When an instance of
[Num](Prelude.html#t:Num)
,[Read](Prelude.html#t:Read)
,[Integral](Prelude.html#t:Integral)
,[Fractional](Prelude.html#t:Fractional)
,[Floating](Prelude.html#t:Floating)
,[RealFrac](Prelude.html#t:RealFrac)
, or[RealFloat](Prelude.html#t:RealFloat)
is defined forCT
, the arithmetic operations defined by the type class implement the same function as the corresponding arithmetic operations (if available) in C ont
. - When an instance of
[Bits](Data-Bits.html#t:Bits)
is defined forCT
, the bitwise operation defined by the type class implement the same function as the corresponding bitwise operation in C ont
.
Integral types
These types are are represented as newtype
s of types in Data.Int and Data.Word, and are instances of[Eq](Prelude.html#t:Eq)
, [Ord](Prelude.html#t:Ord)
, [Num](Prelude.html#t:Num)
, [Read](Prelude.html#t:Read)
,[Show](Prelude.html#t:Show)
, [Enum](Prelude.html#t:Enum)
, [Typeable](Data-Typeable-Internal.html#t:Typeable)
, [Storable](Foreign-Storable.html#t:Storable)
,[Bounded](Prelude.html#t:Bounded)
, [Real](Prelude.html#t:Real)
, [Integral](Prelude.html#t:Integral)
and[Bits](Data-Bits.html#t:Bits)
.
newtype CChar Source
Haskell type representing the C char
type.
newtype CSChar Source
Haskell type representing the C signed char
type.
newtype CUChar Source
Haskell type representing the C unsigned char
type.
newtype CShort Source
Haskell type representing the C short
type.
newtype CUShort Source
Haskell type representing the C unsigned short
type.
newtype CInt Source
Haskell type representing the C int
type.
newtype CUInt Source
Haskell type representing the C unsigned int
type.
newtype CLong Source
Haskell type representing the C long
type.
newtype CULong Source
Haskell type representing the C unsigned long
type.
newtype CPtrdiff Source
Haskell type representing the C ptrdiff_t
type.
newtype CSize Source
Haskell type representing the C size_t
type.
newtype CWchar Source
Haskell type representing the C wchar_t
type.
newtype CLLong Source
Haskell type representing the C long long
type.
newtype CULLong Source
Haskell type representing the C unsigned long long
type.
Numeric types
newtype CClock Source
Haskell type representing the C clock_t
type.
newtype CTime Source
Haskell type representing the C time_t
type.
To convert [CTime](Foreign-C-Types.html#t:CTime)
to [UTCTime](Data-Time.html#t:UTCTime)
, use the following formula:
posixSecondsToUTCTime (realToFrac :: POSIXTime)
Floating types
These types are are represented as newtype
s of[Float](Prelude.html#t:Float)
and [Double](Prelude.html#t:Double)
, and are instances of[Eq](Prelude.html#t:Eq)
, [Ord](Prelude.html#t:Ord)
, [Num](Prelude.html#t:Num)
, [Read](Prelude.html#t:Read)
,[Show](Prelude.html#t:Show)
, [Enum](Prelude.html#t:Enum)
, [Typeable](Data-Typeable-Internal.html#t:Typeable)
, [Storable](Foreign-Storable.html#t:Storable)
,[Real](Prelude.html#t:Real)
, [Fractional](Prelude.html#t:Fractional)
, [Floating](Prelude.html#t:Floating)
,[RealFrac](Prelude.html#t:RealFrac)
and [RealFloat](Prelude.html#t:RealFloat)
.
newtype CFloat Source
Haskell type representing the C float
type.
newtype CDouble Source
Haskell type representing the C double
type.
Other types
data CFile Source
Haskell type representing the C FILE
type.
data CFpos Source
Haskell type representing the C fpos_t
type.