aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test_gen.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/test_gen.c b/test_gen.c
index 12c3c16..e23f86c 100644
--- a/test_gen.c
+++ b/test_gen.c
@@ -19,21 +19,6 @@ struct {
{ LITTLE, "<" },
};
-enum fmt {
- FMT_b,
- FMT_B,
- FMT_h,
- FMT_H,
- FMT_i,
- FMT_I,
- FMT_l,
- FMT_L,
- FMT_q,
- FMT_Q,
- FMT_END,
- FMT_BEGIN = FMT_b,
-};
-
struct fmtinfo {
char fmt;
char *type;
@@ -41,16 +26,16 @@ struct fmtinfo {
uintmax_t max;
size_t size;
} fmtinfo[] = {
- [FMT_b] = { 'b', "signed char", INTMAX_C( -128), UINTMAX_C( 127), 1 },
- [FMT_B] = { 'B', "unsigned char", INTMAX_C( 0), UINTMAX_C( 255), 1 },
- [FMT_h] = { 'h', "signed short", INTMAX_C( -32768), UINTMAX_C( 32767), 2 },
- [FMT_H] = { 'H', "unsigned short", INTMAX_C( 0), UINTMAX_C( 65535), 2 },
- [FMT_i] = { 'i', "signed int", INTMAX_C( -32768), UINTMAX_C( 32767), 2 },
- [FMT_I] = { 'I', "unsigned int", INTMAX_C( 0), UINTMAX_C( 65535), 2 },
- [FMT_l] = { 'l', "signed long", INTMAX_C( -2147483648), UINTMAX_C( 2147483647), 4 },
- [FMT_L] = { 'L', "unsigned long", INTMAX_C( 0), UINTMAX_C( 4294967295), 4 },
- [FMT_q] = { 'q', "signed long long", -INTMAX_C(9223372036854775807) - 1, UINTMAX_C( 9223372036854775807), 8 },
- [FMT_Q] = { 'Q', "unsigned long long", INTMAX_C( 0), UINTMAX_C(18446744073709551615), 8 },
+ { 'b', "signed char", INTMAX_C( -128), UINTMAX_C( 127), 1 },
+ { 'B', "unsigned char", INTMAX_C( 0), UINTMAX_C( 255), 1 },
+ { 'h', "signed short", INTMAX_C( -32768), UINTMAX_C( 32767), 2 },
+ { 'H', "unsigned short", INTMAX_C( 0), UINTMAX_C( 65535), 2 },
+ { 'i', "signed int", INTMAX_C( -32768), UINTMAX_C( 32767), 2 },
+ { 'I', "unsigned int", INTMAX_C( 0), UINTMAX_C( 65535), 2 },
+ { 'l', "signed long", INTMAX_C( -2147483648), UINTMAX_C( 2147483647), 4 },
+ { 'L', "unsigned long", INTMAX_C( 0), UINTMAX_C( 4294967295), 4 },
+ { 'q', "signed long long", -INTMAX_C(9223372036854775807) - 1, UINTMAX_C( 9223372036854775807), 8 },
+ { 'Q', "unsigned long long", INTMAX_C( 0), UINTMAX_C(18446744073709551615), 8 },
};
static char cchar(char c)
@@ -137,13 +122,13 @@ static void unpack_unsigned(FILE *out, const struct fmtinfo *fi, enum endian e,
fprintf(out, "\tCHECK_EQUAL(PRIdMAX, (uintmax_t)v[%d], UINTMAX_C(%" PRIuMAX "));\n", i, testval);
}
-static void unpack_gen(FILE *out, enum fmt fmt, int arraysize)
+static void unpack_gen(FILE *out, size_t fmt, int arraysize)
{
int realsize = arraysize == 0 ? 1 : arraysize;
struct fmtinfo *fi;
bool sign;
- assert(fmt < FMT_END);
+ assert(fmt < sizeof fmtinfo / sizeof fmtinfo[0]);
fi = &fmtinfo[fmt];
@@ -172,7 +157,7 @@ static void unpack_gen(FILE *out, enum fmt fmt, int arraysize)
int main(void)
{
FILE *out = stdout;
- for (enum fmt fmt = FMT_BEGIN; fmt < FMT_END; fmt++) {
+ for (size_t fmt = 0; fmt < sizeof fmtinfo / sizeof fmtinfo[0]; fmt++) {
unpack_gen(out, fmt, 0);
for (int i = 2; i < 4; i++)
unpack_gen(out, fmt, i);