aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2019-03-14 18:35:40 -0700
committerMichael Forney <mforney@mforney.org>2019-03-14 18:35:40 -0700
commit0fdbe052dcf45546e1b78b731ba2529c2b655396 (patch)
treec0b71bc981e3880a41ba848b088a292617802521
parentf8224f9d814b111e9841c8c3e9735046290b55a6 (diff)
downloadcproc-0fdbe052dcf45546e1b78b731ba2529c2b655396.tar.xz
Don't need a table of int maximums
-rw-r--r--expr.c8
1 files changed, 1 insertions, 7 deletions
diff --git a/expr.c b/expr.c
index 7bc7f4e..8b3df82 100644
--- a/expr.c
+++ b/expr.c
@@ -241,12 +241,6 @@ inttype(uint64_t val, bool decimal, char *end)
{&typellong, "ll", NULL},
{&typeullong, "ull", "llu"},
};
- static const uint64_t max[] = {
- [1] = 0xff,
- [2] = 0xffff,
- [4] = 0xffffffff,
- [8] = 0xffffffffffffffff,
- };
struct type *t;
size_t i, step;
@@ -263,7 +257,7 @@ inttype(uint64_t val, bool decimal, char *end)
step = i % 2 || decimal ? 2 : 1;
for (; i < LEN(limits); i += step) {
t = limits[i].type;
- if (val <= max[t->size] >> t->basic.issigned)
+ if (val <= (uint64_t)-1 >> (8 - t->size << 3) + t->basic.issigned)
return t;
}
error(&tok.loc, "no suitable type for constant '%s'", tok.lit);