| Safe Haskell | Safe-Inferred |
|---|---|
| Language | GHC2021 |
HsBindgen.Runtime.CBool
Description
C boolean semantics
In C, boolean types are numeric, where value 0 is considered false and any
other value is considered true. They are implemented differently across
different C projects:
- Since C23, there is a
booltype and predefined constantstrueandfalse. - Since C99, standard header
stdbool.hdefines (implementation-dependent) type_Booland macrostrueandfalse. This header is deprecated since C23. Before C99, users defined boolean types and values, following the common conventions. Some projects still define their own boolean type, perhaps for compatibility with old C standards. Common implementations include the following, where
boolmay be spelled differently (such asBoolorBOOL):An
enumtype:typedef enum { false, true } bool;A
typedefand separateenumvalues:typedef int bool; enum { false, true };A
typedefand macro values:typedef int bool; #define true 1 #define false 0
A macro alias and macro values:
#define bool int #define true 1 #define false 0
This module provides an API that is compatible with bindings generated for
any of these possible implementations. Note that the implementation only
requires Eq and Num instances. Conversion follows C23 semantics: only
value 0 is considered false, and any other value is considered true.
Intended for qualified import.
import HsBindgen.Runtime.CBool qualified as CBool
Synopsis
- true :: Num b => b
- false :: Num b => b
- isTrue :: (Eq b, Num b) => b -> Bool
- isFalse :: (Eq b, Num b) => b -> Bool
- fromBool :: Num b => Bool -> b
- toBool :: (Eq b, Num b) => b -> Bool
- (&&) :: (Eq b, Num b) => b -> b -> b
- (||) :: (Eq b, Num b) => b -> b -> b
- not :: (Eq b, Num b) => b -> b
- bool :: (Eq b, Num b) => a -> a -> b -> a
- if_ :: (Eq b, Num b) => b -> a -> a -> a
- when :: (Eq b, Num b, Applicative f) => b -> f () -> f ()
- unless :: (Eq b, Num b, Applicative f) => b -> f () -> f ()
Values
Predicates
Conversion
Operations
(&&) :: (Eq b, Num b) => b -> b -> b Source #
Boolean and, lazy in the second argument
This function returns one of the standard values.
(||) :: (Eq b, Num b) => b -> b -> b Source #
Boolean or, lazy in the second argument
This function returns one of the standard values.