Simplify sizeof(x) / sizeof(x[0]) to lengthof(x).
authorChristoph Mallon <christoph.mallon@gmx.de>
Fri, 19 Aug 2011 06:48:55 +0000 (08:48 +0200)
committerChristoph Mallon <christoph.mallon@gmx.de>
Fri, 19 Aug 2011 07:01:41 +0000 (09:01 +0200)
driver/firm_opt.c
preprocessor.c
type.c

index e7a94f2..f016adb 100644 (file)
@@ -273,10 +273,10 @@ static void rts_map(void)
                { &rts_entities[rts_memset],  i_mapper_memset },
                { &rts_entities[rts_memcmp],  i_mapper_memcmp }
        };
-       i_record rec[sizeof(mapper)/sizeof(mapper[0])];
-       unsigned i, n_map;
+       i_record rec[lengthof(mapper)];
+       size_t   n_map = 0;
 
-       for (i = n_map = 0; i < sizeof(mapper)/sizeof(mapper[0]); ++i) {
+       for (size_t i = 0; i != lengthof(mapper); ++i) {
                if (*mapper[i].ent != NULL) {
                        rec[n_map].i_call.kind     = INTRINSIC_CALL;
                        rec[n_map].i_call.i_ent    = *mapper[i].ent;
@@ -911,8 +911,7 @@ void firm_option_help(print_option_help_func print_option_help)
                print_option_help(buf, buf2);
        }
 
-       size_t const n_options = sizeof(firm_options)/sizeof(firm_options[0]);
-       for (size_t k = 0; k < n_options; ++k) {
+       for (size_t k = 0; k != lengthof(firm_options); ++k) {
                char buf[1024];
                char buf2[1024];
                snprintf(buf, sizeof(buf), "-f%s", firm_options[k].option);
@@ -942,8 +941,7 @@ int firm_option(const char *const opt)
        }
 
        size_t const len = strlen(opt);
-       size_t const n_options = sizeof(firm_options)/sizeof(firm_options[0]);
-       for (size_t i = n_options; i != 0;) {
+       for (size_t i = lengthof(firm_options); i != 0;) {
                struct params const* const o = &firm_options[--i];
                if (len == o->opt_len && strncmp(opt, o->option, len) == 0) {
                        /* statistic options do accumulate */
index a8cf16d..cc6308b 100644 (file)
@@ -195,8 +195,7 @@ static inline void next_real_char(void)
 {
        assert(input.bufpos <= input.bufend);
        if (input.bufpos >= input.bufend) {
-               size_t n = decode(input.input, input.buf + MAX_PUTBACK,
-                                 sizeof(input.buf)/sizeof(input.buf[0]) - MAX_PUTBACK);
+               size_t const n = decode(input.input, input.buf + MAX_PUTBACK, lengthof(input.buf) - MAX_PUTBACK);
                if (n == 0) {
                        input.c = EOF;
                        return;
diff --git a/type.c b/type.c
index 3864a0d..03c5052 100644 (file)
--- a/type.c
+++ b/type.c
@@ -225,9 +225,7 @@ void init_types(unsigned machine_size)
        props[ATOMIC_TYPE_WCHAR_T]     = props[ATOMIC_TYPE_INT];
 
        /* set struct alignments to the same value as alignment */
-       for (size_t i = 0;
-            i < sizeof(atomic_type_properties)/sizeof(atomic_type_properties[0]);
-            ++i) {
+       for (size_t i = 0; i != lengthof(atomic_type_properties); ++i) {
                props[i].struct_alignment = props[i].alignment;
        }
 }