]> git.ipfire.org Git - thirdparty/make.git/commitdiff
* src/makeint.h: Add an ARRAYLEN macro to compute array sizes
authorPaul Smith <psmith@gnu.org>
Sun, 7 Jan 2024 16:28:23 +0000 (11:28 -0500)
committerPaul Smith <psmith@gnu.org>
Sun, 7 Jan 2024 16:28:23 +0000 (11:28 -0500)
* src/main.c: Replace inline array length computation with ARRAYLEN.
* src/function.c: Ditto.
* src/read.h: Ditto.

src/function.c
src/main.c
src/makeint.h
src/read.c

index 00686f321a0140e66e1d9f7a0c75537b41af5c1a..5e7285a50764751cc0c3703135b2d389b013d732 100644 (file)
@@ -2436,8 +2436,6 @@ static struct function_table_entry function_table_init[] =
   FT_ENTRY ("not",           0,  1,  1,  func_not),
 #endif
 };
-
-#define FUNCTION_TABLE_ENTRIES (sizeof (function_table_init) / sizeof (struct function_table_entry))
 \f
 
 /* These must come after the definition of function_table.  */
@@ -2736,9 +2734,9 @@ define_new_function (const floc *flocp, const char *name,
 void
 hash_init_function_table (void)
 {
-  hash_init (&function_table, FUNCTION_TABLE_ENTRIES * 2,
+  hash_init (&function_table, ARRAYLEN (function_table_init) * 2,
              function_table_entry_hash_1, function_table_entry_hash_2,
              function_table_entry_hash_cmp);
   hash_load (&function_table, function_table_init,
-             FUNCTION_TABLE_ENTRIES, sizeof (struct function_table_entry));
+             ARRAYLEN (function_table_init), sizeof (struct function_table_entry));
 }
index 0e7c53a2b628ebb12055a999c2abb1caf7450599..c9c64b54bceb48a52958cc3251b88429c0b5cc75 100644 (file)
@@ -2898,10 +2898,8 @@ main (int argc, char **argv, char **envp)
 \f
 /* Parsing of arguments, decoding of switches.  */
 
-static char options[1 + sizeof (switches) / sizeof (switches[0]) * 3];
-static struct option long_options[(sizeof (switches) / sizeof (switches[0])) +
-                                  (sizeof (long_option_aliases) /
-                                   sizeof (long_option_aliases[0]))];
+static char options[1 + ARRAYLEN (switches) * 3];
+static struct option long_options[ARRAYLEN (switches) + ARRAYLEN (long_option_aliases)];
 
 /* Fill in the string and vector for getopt.  */
 static void
@@ -2956,9 +2954,7 @@ init_switches (void)
         }
     }
   *p = '\0';
-  for (c = 0; c < (sizeof (long_option_aliases) /
-                   sizeof (long_option_aliases[0]));
-       ++c)
+  for (c = 0; c < ARRAYLEN (long_option_aliases); ++c)
     long_options[i++] = long_option_aliases[c];
   long_options[i].name = 0;
 }
index 6907b2b373d237387d30f401cf45331f111f1cec..00289b9c457c32eac50499e7c635838d182c1f03 100644 (file)
@@ -506,6 +506,9 @@ extern struct rlimit stack_limit;
 
 #define NILF ((floc *)0)
 
+/* Number of elements in an array.  */
+#define ARRAYLEN(_a)          (sizeof (_a) / sizeof ((_a)[0]))
+
 /* Number of characters in a string constant.  Does NOT include the \0 byte.  */
 #define CSTRLEN(_s)           (sizeof (_s)-1)
 
index 33020633bf02b971bc8d7672c24065a46321a2d5..e97d3061bef7779088a06597e5a1d95b91f760ee 100644 (file)
@@ -2964,7 +2964,7 @@ construct_include_path (const char **arg_dirs)
   int disable = 0;
 
   /* Compute the number of pointers we need in the table.  */
-  idx = sizeof (default_include_directories) / sizeof (const char *);
+  idx = ARRAYLEN (default_include_directories);
   if (arg_dirs)
     for (cpp = arg_dirs; *cpp != 0; ++cpp)
       ++idx;