Convert -1 to type T.
If T is a signed type a representation of the value -1 should always exist, since the value 1 also exists.
If T is an unsigned type, the converted value is guaranteed to hold the maximum value that is representable in this type. This is guaranteed to work regardless of the platform's representation of negative values: integer conversion to an unsigned type is always defined to be modulo 2^N where N is the precision of the target type. Return an unsigned version of P99_M1.
The returning expression is of type uintmax_t Generate an integer expression of type T and value X.
This macro is suitable for use in preprocessor conditionals, provided X evaluates to an integer constant.
- Warning:
- Beware that the type information T is simply ignored by the preprocessor because there arithmetic is done with types
intmax_t or uintmax_t. If you want to be sure that it is used as uintmax_t suffix the constant X with an "u" or "U".
-
Don't do bit complement arithmetic in the preprocessor with that, since
uintmax_t might have more bits than T, the result might not be what you expect.
- Parameters:
-
| T | must be a type identifier, just one word that represents a type. |
| X | could be any integer expression that is allowed in the same context. If X evaluates to a pointer value, an error is detected. |
The macro itself uses a dirty trick. In preprocessor context of conditional evaluation the T in the expansion is just an identifier that is unknown to the preprocessor and it is thus replaced by 0. The + sign is thus a binary plus.
In program context (T) is interpreted as a cast. The + sign is thus a prefix to the integer expression. This results in an error when an attempt is made to use this with a pointer value.
Cast the int value 0 to type T
Cast the int value 0 to the unsigned type corresponding to T
Cast the int value 1 to type T
Cast the int value 1 to the unsigned type corresponding to T
Cast the int value 2 to type T
Cast the int value 2 to the unsigned type corresponding to T
Cast the int value 3 to type T
Cast the int value 3 to the unsigned type corresponding to T The maximum representable value of the unsigned type corresponding to T
The returning expression is of type uintmax_t
This is generally not the minimum representable value of the signed type corresponding to T, it might deviate by one from that value.
The returning expression is of type T.
- See also:
- P99_TMIN Determine if T is an unsigned or signed integral type
This works as follows:
- If T is signed then -1 in that type is always less than 0 in that type
- If T is unsigned then conversion of -1 to that type gives the maximally encodable value for that type. This is always greater than 0 in that type,
- If T is
_Bool or equivalent, -1 converted to it results in 1 and 0 is also mapped to 0. Thus it is detected as unsigned.
- See also:
- P99_SIGNED for a similar macro that takes an expression as an argument
Expression A is evaluated exactly once. Expression B is only used for its type and never evaluated.
The result can always be determined at compile time, if A can be determined then, regardless of the actual value of B. But it is only a constant expression in the strict sense of C99 if both A and B are so.
- Warning:
- Due to the integer promotion rules the resulting expression has a width that is at least that of
int, even if A and B have smaller width than that.
Promote the integer value 0 under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value 1 under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value 2 under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value 3 under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value 0U under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value 1u under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value 2u under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion
Promote the integer value -1 under the constraint of expression EXPR
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion Promote the integer value
-1 under the constraint of the unsigned promoted expression EXPR
-
P99_SIGN_PROMOTE for rules about integer sign promotion The maximum representable value of the unsigned type promoted with respect to expression EXPR.
The returning expression is of unsigned integer type.
- See also:
- P99_SIGN_PROMOTE for rules about integer sign promotion Half of the maximum representable value of the unsigned type promoted with respect to expression EXPR
This is the maximum representable value of the signed type promoted with respect to EXPR
The returning expression is of unsigned integer type.
- See also:
- P99_TMAX
-
P99_SIGN_PROMOTE for rules about integer sign promotion The width of the integral type of expression EXPR.
This is the precision plus eventually a sign bit, if the type is signed.
The resulting expression is evaluated at compile time and maybe used int constant expressions.
- Warning:
- These are not necessarily all bits that are used by the type, there might be padding bits.
- See also:
- P99_TWIDTH
-
P99_EPREC
-
P99_EPADDING
-
P99_SIGN_PROMOTE for rules about integer sign promotion Give the maximum representable value of type T
The resulting expression is evaluated at compile time and maybe used int constant expressions.
- Warning:
- this is not necessarily the width of T
- See also:
- P99_TPREC
-
P99_EWIDTH
-
P99_EPADDING
-
P99_SIGN_PROMOTE for rules about integer sign promotion The padding bits of the integral type of expression EXPR.
These are the bits that are not used for the numerical representation of the values. On most architectures and for most types this will be 0. But for e.g for _Bool this will be at least 7.
The resulting expression is evaluated at compile time and maybe used int constant expressions.
- See also:
- P99_TPADDING
-
P99_EWIDTH
-
P99_EPREC
-
P99_SIGN_PROMOTE for rules about integer sign promotion The negative of the half of the maximum representable value of the promoted integral type of expression EXPR
This is generally not the minimum representable value of the signed type corresponding to EXPR, it might deviate by one from that value.
The returning expression is of type T.
- See also:
- P99_TMIN Determine if EXPR has an unsigned or signed integral type
Note that this macro does not evaluate EXPR but uses it only to determine its signedness. There are no side effects.
The result can always be determined at compile time, but it is not a constant expression in the strict sense of C99 if EXPR is not so.
Beware, the result of this expression is not the sign of EXPR, but whether or not the type of it could hold a signed value.
- See also:
- P99_ISSIGNED for a similar macro that takes a type as an argument
-
P99_SIGN_PROMOTE for rules about integer sign promotion
Definition at line 208 of file p99_int.h.
References uintmax_t.