P99
|
Macros handling integer types and initialization. More...
Go to the source code of this file.
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_HTON(N, X) (((P99_PASTE2(p00_endian_, N) const)P99_HTON_INITIALIZER(N, X)).p00_i) |
host to network transformation of integers according to the endianness of the platform More... | |
#define | P99_HTON_INITIALIZER(N, X) { .p00_c = { P00_HTON(N, X) } } |
#define | P99_HTONL(X) P99_HTON(4, X) |
host to network transformation of integers according to the endianness of the platform More... | |
#define | P99_HTONS(X) P99_HTON(2, X) |
host to network transformation of integers according to the endianness of the platform 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_LOW0SET(X) ((X) | ((X) + 1)) |
set least significant zero bit More... | |
#define | P99_LOW2(X) ((X) & -(X)) |
extract the least significant bit that is non zero More... | |
#define | P99_LOW2CLEAR(X) ((X) & ((X) - 1)) |
clear the least significant bit that is non zero More... | |
#define | P99_LOW2FILL(X) ((X) | ((X) - 1)) |
fill all bits below least significant bit that is non zero More... | |
#define | P99_LOW2MASK0(X) (~(X) & ((X) - 1)) |
mask consisting of bits below and including the least significant bit that is non zero More... | |
#define | P99_LOW2MASK1(X) ((X) ^ ((X) - 1)) |
mask consisting of bits strictly below the least significant bit that is non zero More... | |
#define | P99_LOW2SHIFT(X) (P99_LIKELY(!!(X)) ? ((X) / ((X) & -(X))) : 0u) |
shift number right such that the least significant bit that is non zero ends up at bit position 0 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_MASK2LOW0(X) ((X) ^ -(X)) |
mask consisting of bits strictly above the least significant bit that is non zero More... | |
#define | P99_MASK2LOW1(X) ((X) | -(X)) |
mask consisting of bits above and including the least significant bit that is non zero More... | |
#define | P99_NTOH(N, X) (P99_PASTE2(p00_uint_byte_, N) const)P00_NTOH(N, X, ((P99_PASTE2(p00_endian_, N) const)P99_NTOH_INITIALIZER(N, X))) |
network to host transformation of integers according to the endianness of the platform More... | |
#define | P99_NTOH_INITIALIZER(N, X) { .p00_i = (X) } |
#define | P99_NTOHL(X) P99_NTOH(4, X) |
network to host transformation of integers according to the endianness of the platform More... | |
#define | P99_NTOHS(X) P99_NTOH(2, X) |
network to host transformation of integers according to the endianness of the platform 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 |
uintmax_t | p99_low0set (uintmax_t p00_x) |
function equivalent to P99_LOW0SET More... | |
uintmax_t | p99_low2 (uintmax_t p00_x) |
function equivalent to P99_LOW2 More... | |
uintmax_t | p99_low2clear (uintmax_t p00_x) |
function equivalent to P99_LOW2CLEAR More... | |
uintmax_t | p99_low2fill (uintmax_t p00_x) |
function equivalent to P99_LOW2FILL More... | |
uintmax_t | p99_low2mask0 (uintmax_t p00_x) |
function equivalent to P99_LOW2MASK0 More... | |
uintmax_t | p99_low2mask1 (uintmax_t p00_x) |
function equivalent to P99_LOW2MASK1 More... | |
uintmax_t | p99_low2shift (uintmax_t p00_x) |
function equivalent to P99_LOW2SHIFT More... | |
uintmax_t | p99_mask2low0 (uintmax_t p00_x) |
function equivalent to P99_MASK2LOW0 More... | |
uintmax_t | p99_mask2low1 (uintmax_t p00_x) |
function equivalent to P99_MASK2LOW1 More... | |
uintmax_t | p99_next_popcount (uintmax_t p00_x) |
function that returns the next higher value that has exactly the same popcount as x. More... | |
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... | |
Macros handling integer types and initialization.
The initialization features in this file might produce many compiler warnings, such as "missing braces in initializer" or something similar. This is because we have to use a catch all initializer of the form { 0 }
. Such a flattened initializer is explicitly covered by the standard but seems to be considered bad style by some people.
If you use the features of this file and switch all warnings on for such a compiler you will probably have a hard time detecting real and interesting warning for all these initializer warnings. Therefore we switch off such warnings for compilers that we know cause such a problem.
Definition in file p99_int.h.