[PATCH] Don't use nested function in test-ffs
Szabolcs Nagy
szabolcs.nagy@arm.com
Thu Nov 12 08:24:52 GMT 2020
The 11/12/2020 13:27, Siddhesh Poyarekar via Libc-alpha wrote:
> There is no real need to use a nested function in that test, so break
> it out so that it can build with clang too.
> ---
> string/test-ffs.c | 37 ++++++++++++++++++-------------------
> 1 file changed, 18 insertions(+), 19 deletions(-)
>
> diff --git a/string/test-ffs.c b/string/test-ffs.c
> index 0df488fa2b..a2a606522a 100644
> --- a/string/test-ffs.c
> +++ b/string/test-ffs.c
> @@ -21,34 +21,33 @@
> #include <stdio.h>
> #include <string.h>
>
> +void try (const char *name, long long int param, int value, int expected,
> + int *failuresp)
> +{
> + if (value != expected)
> + {
> + printf ("%s(%#llx) expected %d got %d\n",
> + name, param, expected, value);
> + *failuresp += 1;
> + }
> + else
> + printf ("%s(%#llx) as expected %d\n", name, param, value);
> +}
> +
> int
> do_test (void)
> {
> int failures = 0;
> int i;
this works, but i think you can just make failures global.
(then a bit less changes are needed)
>
> - auto void try (const char *name, long long int param, int value,
> - int expected);
> -
> - void try (const char *name, long long int param, int value, int expected)
> - {
> - if (value != expected)
> - {
> - printf ("%s(%#llx) expected %d got %d\n",
> - name, param, expected, value);
> - ++failures;
> - }
> - else
> - printf ("%s(%#llx) as expected %d\n", name, param, value);
> - }
> -
> #define TEST(fct, type) \
> - try (#fct, 0, fct ((type) 0), 0); \
> + try (#fct, 0, fct ((type) 0), 0, &failures); \
> for (i=0 ; i < 8 * sizeof (type); i++) \
> - try (#fct, 1ll << i, fct (((type) 1) << i), i + 1); \
> + try (#fct, 1ll << i, fct (((type) 1) << i), i + 1, &failures); \
> for (i=0 ; i < 8 * sizeof (type) ; i++) \
> - try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1);\
> - try (#fct, 0x80008000, fct ((type) 0x80008000), 16)
> + try (#fct, (~((type) 0) >> i) << i, fct ((~((type) 0) >> i) << i), i + 1, \
> + &failures); \
> + try (#fct, 0x80008000, fct ((type) 0x80008000), 16, &failures)
>
> TEST (ffs, int);
> TEST (ffsl, long int);
> --
> 2.26.2
>
More information about the Libc-alpha
mailing list