P99
Modules | Macros | Typedefs | Enumerations | Functions
Macros to handle integer type expressions
+ Collaboration diagram for Macros to handle integer type expressions:

Modules

 Bitfiddling
 Bit fiddling of low order bits.
 
 Endianess
 Help to handle endianess problems of different kind.
 

Macros

#define P99_0(T)   P99_C(T, 0)
 Cast the int value 0 to type T. More...
 
#define P99_0U(T)   P99_TO_UNSIGN(T, 0)
 Cast the int value 0 to the unsigned type corresponding to T. More...
 
#define P99_1(T)   P99_C(T, 1)
 Cast the int value 1 to type T. More...
 
#define P99_1U(T)   P99_TO_UNSIGN(T, 1)
 Cast the int value 1 to the unsigned type corresponding to T. More...
 
#define P99_2(T)   P99_C(T, 2)
 Cast the int value 2 to type T. More...
 
#define P99_2COMPLEMENT(T)   (P99_SIGNED_REPRESENTATION(T) == p99_signed_representation_twos)
 If the sign representation of a type is two's complement the type has no negative zero and can thus represent one more value. More...
 
#define P99_2U(T)   P99_TO_UNSIGN(T, 2)
 Cast the int value 2 to the unsigned type corresponding to T. More...
 
#define P99_3(T)   P99_C(T, 3)
 Cast the int value 3 to type T. More...
 
#define P99_3U(T)   P99_TO_UNSIGN(T, 3)
 Cast the int value 3 to the unsigned type corresponding to T. More...
 
#define P99_ABS(EXPR)   (P99_SIGNED(EXPR) ? p00_abs_signed(EXPR) : P99_C(uintmax_t, EXPR))
 Compute the absolute value of an integral expression. More...
 
#define P99_AVAL(T)   P00_RVAL2_(T)
 Define an lvalue of array type T with unknown base type. More...
 
#define P99_C(T, X)   ((T)+(X))
 Generate an integer expression of type T and value X. More...
 
#define P99_CHOOSE5(xT, cc, cs, ci, cl, cll)
 
#define P99_E_2COMPLEMENT(EXPR)   P99_SIGN_PROMOTE(P99_E_REPRESENTATION(EXPR) == p99_signed_representation_twos, (EXPR))
 If the sign representation of a type is two's complement the type has no negative zero and can thus represent one more value. More...
 
#define P99_E_REPRESENTATION(EXPR)   ((p99_signed_representation)(P99_PROMOTE_M1(EXPR) & P99_PROMOTE_3(EXPR)))
 C99 allows for exactly three different possibilities for the encoding of negative values of integer types. More...
 
#define P99_EMAX(EXPR)   (P99_SIGNED(EXPR) ? P99_SE_MAX(EXPR) : P99_PROMOTE_M1(EXPR))
 Give the maximum representable value of the type of the expression EXPR. More...
 
#define P99_EMIN(EXPR)   (P99_SIGNED(EXPR) ? (P00_SE_MIN1(EXPR) - P99_E_2COMPLEMENT(EXPR)) : P99_PROMOTE_0(EXPR))
 Give the minimum representable value of the type of the expression EXPR. More...
 
#define P99_EPADDING(EXPR)   (sizeof(P99_PROMOTE_0(EXPR))*CHAR_BIT - P99_EWIDTH(EXPR))
 The padding bits of the integral type of expression EXPR. More...
 
#define P99_EPREC(EXPR)   (P99_EWIDTH(EXPR) - P99_SIGNED(EXPR))
 The precision, i.e the number of significant bits in the integral type of expression EXPR. More...
 
#define P99_EWIDTH(EXPR)
 The width of the integral type of expression EXPR. More...
 
#define P99_EWIDTH(EXPR)   P99_HIGH2_1(P99_UE_MAX(EXPR))
 The width of the integral type of expression EXPR. More...
 
#define P99_HIGH2(X)
 
#define P99_HIGH2_1(X)   ((X) == P99_UINTMAX_MAX ? P99_UINTMAX_WIDTH : (P99_HIGH2((X) + UINTMAX_C(1))))
 
#define P99_HMASK(N, M)   (P99_PASTE2(P00_MASK_, N)^P99_PASTE2(P00_MASK_, P99_MINUS(N, M)))
 A mask for the higher M bits in an N bit word. More...
 
#define P99_INIT   { 0 }
 A catch all 0-initializer. More...
 
#define P99_ISSIGNED(T)   (P99_M1(T) < P99_1(T))
 Determine if T is an unsigned or signed integral type. More...
 
#define P99_LVAL(...)
 Define an lvalue of type T, where T is the first parameter in the variable parameter list. More...
 
#define P99_M1(T)   ((T)-1)
 Convert -1 to type T. More...
 
#define P99_M1U(T)   (P99_ISSIGNED(T) ? P99_TO_UNSIGN(T, -1) : P99_C(uintmax_t, P99_M1(T)))
 Return an unsigned version of P99_M1. More...
 
#define P99_PRI(xT, F, LEN)
 
#define P99_PROMOTE_0(EXPR)   P99_SIGN_PROMOTE(0, (EXPR))
 Promote the integer value 0 under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_0U(EXPR)   P99_SIGN_PROMOTE(0U, (EXPR))
 Promote the integer value 0U under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_1(EXPR)   P99_SIGN_PROMOTE(1, (EXPR))
 Promote the integer value 1 under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_1U(EXPR)   P99_SIGN_PROMOTE(1U, (EXPR))
 Promote the integer value 1u under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_2(EXPR)   P99_SIGN_PROMOTE(2, (EXPR))
 Promote the integer value 2 under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_2U(EXPR)   P99_SIGN_PROMOTE(2U, (EXPR))
 Promote the integer value 2u under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_3(EXPR)   P99_SIGN_PROMOTE(3, (EXPR))
 Promote the integer value 3 under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_M1(EXPR)   P99_SIGN_PROMOTE(-1, (EXPR))
 Promote the integer value -1 under the constraint of expression EXPR. More...
 
#define P99_PROMOTE_M1U(EXPR)   P99_SIGN_PROMOTE(P99_PROMOTE_M1(EXPR), P99_PROMOTE_0U(EXPR))
 Promote the integer value -1 under the constraint of the unsigned promoted expression EXPR. More...
 
#define P99_RVAL(T, VAL)
 Define an rvalue of type T and (if given) value VAL. More...
 
#define P99_SE_MAX(EXPR)
 
#define P99_SIGN_PROMOTE(A, B)   (1 ? (A) : (B))
 Compute expression A and apply integer promotion rules under the constraint of expression B. More...
 
#define P99_SIGNED(EXPR)   (P99_PROMOTE_M1(EXPR) < P99_PROMOTE_1(EXPR))
 Determine if EXPR has an unsigned or signed integral type. More...
 
#define P99_SIGNED_REPRESENTATION(T)   P99_C(p99_signed_representation, (P99_M1(T) & P99_3(T)))
 C99 allows exactly three different possibilities for the encoding of negative values of integer types. More...
 
#define P99_TMAX(T)
 Give the maximum representable value of type T. More...
 
#define P99_TMAX(T)   P99_C(T, P99_ISSIGNED(T) ? P99_UT_MAX1(T) : P99_UT_MAX(T))
 Give the maximum representable value of type T. More...
 
#define P99_TMIN(T)
 Give the minimum representable value of type T. More...
 
#define P99_TMIN(T)   P99_C(T, P99_ISSIGNED(T) ? (P00_ST_MIN1(T) - P99_2COMPLEMENT(T)) : P99_0(T))
 Give the minimum representable value of type T. More...
 
#define P99_TO_UNSIGN(T, VAL)
 
#define P99_TO_UNSIGNED(T, MACRO)
 Apply the type macro MACRO to an unsigned type that is compatible with type T. More...
 
#define P99_TPADDING(T)   ((sizeof(T)*CHAR_BIT) - P99_TWIDTH(T))
 The padding bits of integral type T. More...
 
#define P99_TPREC(T)
 The precision, i.e the number of significant bits of integral type T. More...
 
#define P99_TWIDTH(T)   (P99_TPREC(T) + P99_ISSIGNED(T))
 The width of integral type T. More...
 
#define P99_UE_MAX(EXPR)   (P99_PROMOTE_M1U(EXPR))
 The maximum representable value of the unsigned type promoted with respect to expression EXPR. More...
 
#define P99_UE_MAX1(EXPR)   (P99_UE_MAX(EXPR)/P99_PROMOTE_2U(EXPR))
 Half of the maximum representable value of the unsigned type promoted with respect to expression EXPR. More...
 
#define P99_UT_MAX(T)   (P99_M1U(T))
 The maximum representable value of the unsigned type corresponding to T. More...
 
#define P99_UT_MAX1(T)   (P99_UT_MAX(T)/2u)
 Half of the maximum representable value of the unsigned type corresponding to T. More...
 
#define P99X_ABS   P00_ABS
 Compute the absolute value of an integral expression, using integers with extended width. More...
 
#define PTRDIFF_C(X)   P99_C(ptrdiff_t, X)
 Cast the integer value X to type ptrdiff_t , compatible with the preprocessor. More...
 
#define SIZE_C(X)   P99_C(size_t, X)
 Cast the integer value X to type size_t , compatible with the preprocessor. More...
 
#define WCHAR_C(X)   P99_C(wchar_t, X)
 Cast the integer value X to type wchar_t , compatible with the preprocessor. More...
 
#define WINT_C(X)   P99_C(wint_t, X)
 Cast the integer value X to type wint_t , compatible with the preprocessor. More...
 

Typedefs

typedef extendedInt p99x_int128
 A signed integer type of width 128 that exceeds the C99 specifications. More...
 
typedef intmax_t p99x_intmax
 A signed integer type of maximal width that exceeds the C99 specifications. More...
 
typedef extendedInt p99x_uint128
 An unsigned integer type of width 128 that exceeds the C99 specifications. More...
 
typedef uintmax_t p99x_uintmax
 An unsigned integer type of maximal width that exceeds the C99 specifications. More...
 

Enumerations

enum  p99_signed_representation { p99_signed_representation_invalid = 0, p99_signed_representation_magnitude = 1, p99_signed_representation_ones = 2, p99_signed_representation_twos = 3 }
 C99 allows exactly three different possibilities for the encoding of negative values of integer types. More...
 

Functions

p99_inline P99_BUILTIN_TYPE (,) p99_add(P99_BUILTIN_TYPE(
 
p99_inline P99_BUILTIN_TYPE (c,) p99_addc(P99_BUILTIN_TYPE(c
 
p99_inline P99_BUILTIN_TYPE (h,) p99_addh(P99_BUILTIN_TYPE(h
 
p99_inline P99_BUILTIN_TYPE (hh,) p99_addhh(P99_BUILTIN_TYPE(hh
 
p99_inline P99_BUILTIN_TYPE (l,) p99_addl(P99_BUILTIN_TYPE(l
 
p99_inline P99_BUILTIN_TYPE (ll,) p99_addll(P99_BUILTIN_TYPE(ll
 
signed p99_twos (P00_P99_PASTEP00_ARG(BUILTIN_TYPE_, u,, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)(BUILTIN_TYPE_, u,) p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type. More...
 
char p99_twosc (P00_P99_PASTEP00_ARG(BUILTIN_TYPE_, u, c, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)(BUILTIN_TYPE_, u, c) p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type. More...
 
signed short p99_twosh (P00_P99_PASTEP00_ARG(BUILTIN_TYPE_, u, h, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)(BUILTIN_TYPE_, u, h) p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type. More...
 
signed char p99_twoshh (P00_P99_PASTEP00_ARG(BUILTIN_TYPE_, u, hh, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)(BUILTIN_TYPE_, u, hh) p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type. More...
 
signed long p99_twosl (P00_P99_PASTEP00_ARG(BUILTIN_TYPE_, u, l, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)(BUILTIN_TYPE_, u, l) p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type. More...
 
signed long long p99_twosll (P00_P99_PASTEP00_ARG(BUILTIN_TYPE_, u, ll, 158, 157, 156, 155, 154, 153, 152, 151, 150, 149, 148, 147, 146, 145, 144, 143, 142, 141, 140, 139, 138, 137, 136, 135, 134, 133, 132, 131, 130, 129, 128, 127, 126, 125, 124, 123, 122, 121, 120, 119, 118, 117, 116, 115, 114, 113, 112, 111, 110, 109, 108, 107, 106, 105, 104, 103, 102, 101, 100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, 74, 73, 72, 71, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0,)(BUILTIN_TYPE_, u, ll) p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type. More...
 

Detailed Description

The macros here help with integer handling, e.g to detect if a type or expression is signed, what the maximum and minimum values are etc.

uintmax_t
uintmax_t
Definition: p99_str.h:117
P99_IF_LE
#define P99_IF_LE(A, B)
Test two decimal numbers A and B for whether A is less than or equal to B.
Definition: p99_if.h:114
P99_HIGH2_1
#define P99_HIGH2_1(X)
Definition: p99_int.h:208
P99_EPREC
#define P99_EPREC(EXPR)
The precision, i.e the number of significant bits in the integral type of expression EXPR.
Definition: p99_int.h:566
f
f
Definition: p99_str.h:138
P99_TMAX
#define P99_TMAX(T)
Give the maximum representable value of type T.
Definition: p99_int.h:725
P99_RVAL
#define P99_RVAL(T, VAL)
Define an rvalue of type T and (if given) value VAL.
Definition: p99_int.h:1121
P99_PROMOTE_1
#define P99_PROMOTE_1(EXPR)
Promote the integer value 1 under the constraint of expression EXPR.
Definition: p99_int.h:454
unsigned
void unsigned(void)
P99_NARG
#define P99_NARG(...)
Return the length of the variable length argument list, where an empty argument list is considered to...
Definition: p99_args.h:117
P99_INIT
#define P99_INIT
A catch all 0-initializer.
Definition: p99_int.h:1065
P99_CHOOSE5
#define P99_CHOOSE5(xT, cc, cs, ci, cl, cll)
Definition: p99_int.h:1160
d
d
Definition: p99_str.h:138
long
long long
Definition: p99_str.h:69
P99_EWIDTH
#define P99_EWIDTH(EXPR)
The width of the integral type of expression EXPR.
Definition: p99_int.h:551