[PATCH] tst-strftime2: Define the number of elements in each array

TAMUKI Shoichi tamuki@linet.gr.jp
Wed Feb 6 03:29:00 GMT 2019


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];
 
 static void
 mkreftable (void)
@@ -51,9 +54,9 @@ mkreftable (void)
   static const int yrj[] = { 63, 64, 1, 2, 9, 10 };
   static const int yrb[] = { 2531, 2532, 2532, 2533, 2540, 2541 };
 
-  for (i = 0; i < array_length (locales); i++)
-    for (j = 0; j < array_length (formats); j++)
-      for (k = 0; k < array_length (dates); k++)
+  for (i = 0; i < nlocales; i++)
+    for (j = 0; j < nformats; j++)
+      for (k = 0; k < ndates; k++)
 	{
 	  if (i == 0)
 	    {
@@ -93,7 +96,7 @@ do_test (void)
   size_t r, e;
 
   mkreftable ();
-  for (i = 0; i < array_length (locales); i++)
+  for (i = 0; i < nlocales; i++)
     {
       if (setlocale (LC_ALL, locales[i]) == NULL)
 	{
@@ -101,9 +104,9 @@ do_test (void)
 	  continue;
 	}
       printf ("[%s]\n", locales[i]);
-      for (j = 0; j < array_length (formats); j++)
+      for (j = 0; j < nformats; j++)
 	{
-	  for (k = 0; k < array_length (dates); k++)
+	  for (k = 0; k < ndates; k++)
 	    {
 	      ttm.tm_mday = dates[k].d;
 	      ttm.tm_mon  = dates[k].m;
-- 
2.2.1



More information about the Libc-alpha mailing list