This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] tst-strftime2: Define the number of elements in each array
- From: Florian Weimer <fweimer at redhat dot com>
- To: TAMUKI Shoichi <tamuki at linet dot gr dot jp>
- Cc: libc-alpha at sourceware dot org
- Date: Wed, 06 Feb 2019 11:10:05 +0100
- Subject: Re: [PATCH] tst-strftime2: Define the number of elements in each array
- References: <201902060329.AA04230@tamuki.linet.gr.jp>
* TAMUKI Shoichi:
> Define the number of elements in each array (locales, formats, dates)
> as nlocales, nformats, ndates, respectively, so that the array for
> reference is declared using them in stead of magic numbers.
>
> ChangeLog:
>
> * time/tst-strftime2.c: Define the number of elements in each array
> (locales, formats, dates) as nlocales, nformats, ndates, respectively,
> so that the array for reference is declared using them in stead of
> magic numbers.
> ---
> time/tst-strftime2.c | 17 ++++++++++-------
> 1 file changed, 10 insertions(+), 7 deletions(-)
>
> diff --git a/time/tst-strftime2.c b/time/tst-strftime2.c
> index 57d2144..6c2d359 100644
> --- a/time/tst-strftime2.c
> +++ b/time/tst-strftime2.c
> @@ -25,8 +25,10 @@
> #include <string.h>
>
> static const char *locales[] = { "ja_JP.UTF-8", "lo_LA.UTF-8", "th_TH.UTF-8" };
> +#define nlocales array_length (locales)
>
> static const char *formats[] = { "%EY", "%_EY", "%-EY" };
> +#define nformats array_length (formats)
>
> static const struct
> {
> @@ -40,8 +42,9 @@ static const struct
> { 1, 3, 97 },
> { 1, 3, 98 }
> };
> +#define ndates array_length (dates)
>
> -static char ref[3][3][6][100];
> +static char ref[nlocales][nformats][ndates][100];
I'd suggest using array_length only in this place. It's true that
array_length (locales) is more to type than nlocales, but I think it's
clearer to readers because they do not have to look up the definition of
nlocales.
Thanks,
Florian