]> git.draconx.ca Git - cdecl99.git/blobdiff - t/declgen.c
Avoid the use of for loop declarations.
[cdecl99.git] / t / declgen.c
index 459a68e077ae19958ef5d8ce2d2651e75df22b67..4526c0ee69f0f86cc047c5066705600f91e5b07b 100644 (file)
@@ -79,15 +79,15 @@ struct cdecl *new_cdecl(struct cdecl *next)
 char *gen_identifier(struct test_rng *rng)
 {
        static const char valid[59] = "_bcdefghijklmpqrsuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+       size_t i, n;
        char *str;
-       size_t n;
 
        n = test_rng_uniform_int(rng, 10)+1;
        str = malloc_nofail(n+1);
 
        /* Exclude 10 digits from the first character. */
        str[0] = valid[test_rng_uniform_int(rng, sizeof valid - 10)];
-       for (size_t i = 1; i < n; i++)
+       for (i = 1; i < n; i++)
                str[i] = valid[test_rng_uniform_int(rng, sizeof valid)];
        str[n] = 0;
 
@@ -208,13 +208,13 @@ retry:
 struct cdecl_declspec *
 gen_randomize_specs(struct test_rng *rng, struct cdecl_declspec *specs)
 {
-       struct cdecl_declspec **p;
-       size_t n = 0;
+       struct cdecl_declspec *s, **p;
+       size_t i, n = 0;
 
        if (!specs)
                return specs;
 
-       for (struct cdecl_declspec *s = specs; s; s = s->next)
+       for (s = specs; s; s = s->next)
                n++;
 
        p = malloc_nofail((n+1) * sizeof *p);
@@ -222,11 +222,11 @@ gen_randomize_specs(struct test_rng *rng, struct cdecl_declspec *specs)
        /* Build a temporary array for easy element swapping. */
        p[0] = specs;
        p[n] = NULL;
-       for (size_t i = 1; i < n; i++)
+       for (i = 1; i < n; i++)
                p[i] = p[i-1]->next;
 
        /* Knuth shuffle. */
-       for (size_t i = 0; i < n; i++) {
+       for (i = 0; i < n; i++) {
                struct cdecl_declspec *tmp;
                size_t r;
                
@@ -237,7 +237,7 @@ gen_randomize_specs(struct test_rng *rng, struct cdecl_declspec *specs)
        }
 
        /* Fix up the pointers. */
-       for (size_t i = 1; i <= n; i++)
+       for (i = 1; i <= n; i++)
                p[i-1]->next = p[i];
        specs = p[0];
 
@@ -290,8 +290,9 @@ static uintmax_t gen_uintmax(struct test_rng *rng)
 {
        unsigned char tmp;
        uintmax_t ret = 0;
+       size_t i;
 
-       for (size_t i = 0; i < sizeof ret; i++) {
+       for (i = 0; i < sizeof ret; i++) {
                tmp = test_rng_uniform_int(rng, UCHAR_MAX+1);
                ret <<= CHAR_BIT;
                ret |= tmp;