diff options
Diffstat (limited to 'gl/intprops.h')
| -rw-r--r-- | gl/intprops.h | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/gl/intprops.h b/gl/intprops.h index 43734f34..924b6f9a 100644 --- a/gl/intprops.h +++ b/gl/intprops.h | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* intprops.h -- properties of integer types | 1 | /* intprops.h -- properties of integer types |
| 2 | 2 | ||
| 3 | Copyright (C) 2001-2024 Free Software Foundation, Inc. | 3 | Copyright (C) 2001-2026 Free Software Foundation, Inc. |
| 4 | 4 | ||
| 5 | This program is free software: you can redistribute it and/or modify it | 5 | This program is free software: you can redistribute it and/or modify it |
| 6 | under the terms of the GNU Lesser General Public License as published | 6 | under the terms of the GNU Lesser General Public License as published |
| @@ -34,6 +34,14 @@ | |||
| 34 | signed or floating type. Do not evaluate E. */ | 34 | signed or floating type. Do not evaluate E. */ |
| 35 | #define EXPR_SIGNED(e) _GL_EXPR_SIGNED (e) | 35 | #define EXPR_SIGNED(e) _GL_EXPR_SIGNED (e) |
| 36 | 36 | ||
| 37 | /* The same value as as the arithmetic expression E, but with E's type | ||
| 38 | after integer promotions. For example, if E is of type 'enum {A, B}' | ||
| 39 | then 'switch (INT_PROMOTE (E))' pacifies gcc -Wswitch-enum if some | ||
| 40 | enum values are deliberately omitted from the switch's cases. | ||
| 41 | Here, unary + is safer than a cast or inline function, as unary + | ||
| 42 | does only integer promotions and is disallowed on pointers. */ | ||
| 43 | #define INT_PROMOTE(e) (+ (e)) | ||
| 44 | |||
| 37 | 45 | ||
| 38 | /* Minimum and maximum values for integer types and expressions. */ | 46 | /* Minimum and maximum values for integer types and expressions. */ |
| 39 | 47 | ||
| @@ -197,11 +205,11 @@ | |||
| 197 | || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) | 205 | || INT_MULTIPLY_RANGE_OVERFLOW (a, b, min, max)) |
| 198 | #endif | 206 | #endif |
| 199 | #define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ | 207 | #define _GL_DIVIDE_OVERFLOW(a, b, min, max) \ |
| 200 | ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ | 208 | ((min) < 0 ? (b) == _GL_INT_CONVERT (min, -1) && (a) < - (max) \ |
| 201 | : (a) < 0 ? (b) <= (a) + (b) - 1 \ | 209 | : (a) < 0 ? (b) <= (a) + (b) - 1 \ |
| 202 | : (b) < 0 && (a) + (b) <= (a)) | 210 | : (b) < 0 && (a) + (b) <= (a)) |
| 203 | #define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ | 211 | #define _GL_REMAINDER_OVERFLOW(a, b, min, max) \ |
| 204 | ((min) < 0 ? (b) == _GL_INT_NEGATE_CONVERT (min, 1) && (a) < - (max) \ | 212 | ((min) < 0 ? (b) == _GL_INT_CONVERT (min, -1) && (a) < - (max) \ |
| 205 | : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ | 213 | : (a) < 0 ? (a) % (b) != ((max) - (b) + 1) % (b) \ |
| 206 | : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) | 214 | : (b) < 0 && ! _GL_UNSIGNED_NEG_MULTIPLE (a, b, max)) |
| 207 | 215 | ||
