P99
Modules | Defines | Typedefs | Enumerations | Functions
Macros to handle integer type expressions
C Programming facilities
+ 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.


Defines

#define P99_0(T)   P99_C(T, 0)
 Cast the int value 0 to type T.
#define P99_0U(T)   P99_TO_UNSIGNED(T, P99_0)
 Cast the int value 0 to the unsigned type corresponding to T.
#define P99_1(T)   P99_C(T, 1)
 Cast the int value 1 to type T.
#define P99_1U(T)   P99_TO_UNSIGNED(T, P99_1)
 Cast the int value 1 to the unsigned type corresponding to T.
#define P99_2(T)   P99_C(T, 2)
 Cast the int value 2 to type T.
#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.
#define P99_2U(T)   P99_TO_UNSIGNED(T, P99_2)
 Cast the int value 2 to the unsigned type corresponding to T.
#define P99_3(T)   P99_C(T, 3)
 Cast the int value 3 to type T.
#define P99_3U(T)   P99_TO_UNSIGNED(T, P99_3)
 Cast the int value 3 to the unsigned type corresponding to T.
#define P99_ABS(EXPR)   (P99_SIGNED(EXPR) ? p00_abs_signed(EXPR) : P99_C(uintmax_t, EXPR))
 Compute the absolute value of an integral expression.
#define P99_AVAL(T)   P00_RVAL2_(T)
 Define an lvalue of array type T with unknown base type.
#define P99_C(T, X)   ((T)+(X))
 Generate an integer expression of type T and value X.
#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.
#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.
#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.
#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.
#define P99_EPADDING(EXPR)   (sizeof(P99_PROMOTE_0(EXPR))*CHAR_BIT - P99_EWIDTH(EXPR))
 The padding bits of the integral type of expression EXPR.
#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.
#define P99_EWIDTH(EXPR)
 The width of the integral type of expression EXPR.
#define P99_EWIDTH(EXPR)   P99_HIGH2_1(P99_UE_MAX(EXPR))
 The width of the integral type of expression EXPR.
#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.
#define P99_INIT   { 0 }
 A catch all 0-initializer.
#define P99_ISSIGNED(T)   (P99_M1(T) < P99_1(T))
 Determine if T is an unsigned or signed integral type.
#define P99_LVAL(...)   P99_IF_LE(P99_NARG(__VA_ARGS__),1)(P00_LVAL1(__VA_ARGS__))(P00_LVAL(__VA_ARGS__))
 Define an lvalue of type T, where T is the first parameter in the variable parameter list.
#define P99_M1(T)   ((T)-1)
 Convert -1 to type T.
#define P99_M1U(T)   (P99_ISSIGNED(T) ? P99_TO_UNSIGNED(T, P99_M1) : P99_C(uintmax_t, P99_M1(T)))
 Return an unsigned version of P99_M1.
#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.
#define P99_PROMOTE_0U(EXPR)   P99_SIGN_PROMOTE(0U, (EXPR))
 Promote the integer value 0U under the constraint of expression EXPR.
#define P99_PROMOTE_1(EXPR)   P99_SIGN_PROMOTE(1, (EXPR))
 Promote the integer value 1 under the constraint of expression EXPR.
#define P99_PROMOTE_1U(EXPR)   P99_SIGN_PROMOTE(1U, (EXPR))
 Promote the integer value 1u under the constraint of expression EXPR.
#define P99_PROMOTE_2(EXPR)   P99_SIGN_PROMOTE(2, (EXPR))
 Promote the integer value 2 under the constraint of expression EXPR.
#define P99_PROMOTE_2U(EXPR)   P99_SIGN_PROMOTE(2U, (EXPR))
 Promote the integer value 2u under the constraint of expression EXPR.
#define P99_PROMOTE_3(EXPR)   P99_SIGN_PROMOTE(3, (EXPR))
 Promote the integer value 3 under the constraint of expression EXPR.
#define P99_PROMOTE_M1(EXPR)   P99_SIGN_PROMOTE(-1, (EXPR))
 Promote the integer value -1 under the constraint of expression EXPR.
#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.
#define P99_RVAL(T, VAL)
 Define an rvalue of type T and (if given) value VAL.
#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.
#define P99_SIGNED(EXPR)   (P99_PROMOTE_M1(EXPR) < P99_PROMOTE_1(EXPR))
 Determine if EXPR has an unsigned or signed integral type.
#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.
#define P99_TMAX(T)
 Give the maximum representable value of type T.
#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.
#define P99_TMIN(T)
 Give the minimum representable value of type T.
#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.
#define P99_TO_UNSIGNED(T, MACRO)
 Apply the type macro MACRO to an unsigned type that is compatible with type T.
#define P99_TPADDING(T)   ((sizeof(T)*CHAR_BIT) - P99_TWIDTH(T))
 The padding bits of integral type T.
#define P99_TPREC(T)
 The precision, i.e the number of significant bits of integral type T.
#define P99_TWIDTH(T)   (P99_TPREC(T) + P99_ISSIGNED(T))
 The width of integral type T.
#define P99_UE_MAX(EXPR)   (P99_PROMOTE_M1U(EXPR))
 The maximum representable value of the unsigned type promoted with respect to expression EXPR.
#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.
#define P99_UT_MAX(T)   (P99_M1U(T))
 The maximum representable value of the unsigned type corresponding to T.
#define P99_UT_MAX1(T)   (P99_UT_MAX(T)/2u)
 Half of the maximum representable value of the unsigned type corresponding to T.

Typedefs

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

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

signed p99_add (signed p00_a, signed p00_b, int *p00_err)
char p99_addc (char p00_a, char p00_b, int *p00_err)
signed short p99_addh (signed short p00_a, signed short p00_b, int *p00_err)
signed char p99_addhh (signed char p00_a, signed char p00_b, int *p00_err)
signed long p99_addl (signed long p00_a, signed long p00_b, int *p00_err)
signed long long p99_addll (signed long long p00_a, signed long long p00_b, int *p00_err)
signed p99_twos (unsigned p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type.
char p99_twosc (unsigned char p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type.
signed short p99_twosh (unsigned short p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type.
signed char p99_twoshh (unsigned char p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type.
signed long p99_twosl (unsigned long p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type.
signed long long p99_twosll (unsigned long long p00_a)
 Cast an unsigned type into a signed one as would do a two's complement representation of the signed type.

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.

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines