This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch to use ARRAY_SIZE in more places


Simple grep turned up a few more places where we could use the more
legible ARRAY_SIZE in lieu of the explicit verbose sizeof/sizeof
calculation.  Bootstrapped on solaris2.7 (minus ada though.)

Ok to install?

		Thanks,
		--Kaveh


2002-06-20  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

ada:
	* utils.c (init_gigi_decls): Use ARRAY_SIZE in lieu of explicit
	array size calculation.

gcc:
	* c-decl.c (c_decode_option): Use ARRAY_SIZE in lieu of explicit
	array size calculation.
	* gengtype.c (NUM_BASE_FILES, create_file, write_gc_root):
	Likewise.

cp:
	* spew.c (remove_last_token): Use ARRAY_SIZE in lieu of explicit
	array size calculation.

diff -rup orig/egcc-CVS20020619/gcc/ada/utils.c egcc-CVS20020619/gcc/ada/utils.c
--- orig/egcc-CVS20020619/gcc/ada/utils.c	2002-06-04 07:02:39.000000000 -0400
+++ egcc-CVS20020619/gcc/ada/utils.c	2002-06-19 21:51:52.912538325 -0400
@@ -625,13 +625,12 @@ init_gigi_decls (long_long_float_type, e
 						      endlink))),
 	   NULL_TREE, 0, 1, 1, 0);
 
-      for (i = 0; i < sizeof gnat_raise_decls / sizeof gnat_raise_decls[0];
-	   i++)
+      for (i = 0; i < ARRAY_SIZE (gnat_raise_decls); i++)
 	gnat_raise_decls[i] = decl;
     }
   else
     /* Otherwise, make one decl for each exception reason.  */
-    for (i = 0; i < sizeof gnat_raise_decls / sizeof gnat_raise_decls[0]; i++)
+    for (i = 0; i < ARRAY_SIZE (gnat_raise_decls); i++)
       {
 	char name[17];
 
@@ -656,7 +655,7 @@ init_gigi_decls (long_long_float_type, e
     = build_qualified_type (TREE_TYPE (raise_nodefer_decl),
 			    TYPE_QUAL_VOLATILE);
 
-  for (i = 0; i < sizeof gnat_raise_decls / sizeof gnat_raise_decls[0]; i++)
+  for (i = 0; i < ARRAY_SIZE (gnat_raise_decls); i++)
     {
       TREE_THIS_VOLATILE (gnat_raise_decls[i]) = 1;
       TREE_SIDE_EFFECTS (gnat_raise_decls[i]) = 1;
diff -rup orig/egcc-CVS20020619/gcc/c-decl.c egcc-CVS20020619/gcc/c-decl.c
--- orig/egcc-CVS20020619/gcc/c-decl.c	2002-06-16 16:00:39.000000000 -0400
+++ egcc-CVS20020619/gcc/c-decl.c	2002-06-19 21:51:52.932538251 -0400
@@ -697,7 +697,7 @@ c_decode_option (argc, argv)
   else
     {
       size_t i;
-      for (i = 0; i < sizeof (warn_options) / sizeof (warn_options[0]); i++)
+      for (i = 0; i < ARRAY_SIZE (warn_options); i++)
 	if (strncmp (p, "-W", 2) == 0 
 	    && warn_options[i].flag
 	    && (strcmp (p+2, warn_options[i].option) == 0
diff -rup orig/egcc-CVS20020619/gcc/cp/spew.c egcc-CVS20020619/gcc/cp/spew.c
--- orig/egcc-CVS20020619/gcc/cp/spew.c	2002-06-04 07:03:40.000000000 -0400
+++ egcc-CVS20020619/gcc/cp/spew.c	2002-06-19 21:51:52.932538251 -0400
@@ -1062,7 +1062,7 @@ remove_last_token (t)
       for (tc = &t->tokens; (*tc)->next != NULL; tc = &(*tc)->next)
 	;
       *tc = NULL;
-      t->last_pos = sizeof ((*tc)->toks) / sizeof ((*tc)->toks[0]);
+      t->last_pos = ARRAY_SIZE ((*tc)->toks);
     }
   return result;
 }
diff -rup orig/egcc-CVS20020619/gcc/gengtype.c egcc-CVS20020619/gcc/gengtype.c
--- orig/egcc-CVS20020619/gcc/gengtype.c	2002-06-19 21:51:46.032132450 -0400
+++ egcc-CVS20020619/gcc/gengtype.c	2002-06-19 21:51:52.942538224 -0400
@@ -525,7 +525,7 @@ enum {
 static const char *const lang_names[] = {
   "c", "objc", "cp", "treelang", "cobol", "f", "ada", "java"
 };
-#define NUM_BASE_FILES (sizeof (lang_names) / sizeof (lang_names[0]))
+#define NUM_BASE_FILES ARRAY_SIZE (lang_names)
 outf_p base_files[NUM_BASE_FILES];
 
 static outf_p create_file PARAMS ((const char *, const char *));
@@ -570,7 +570,7 @@ create_file (name, oname)
   output_files = f;
 
   oprintf (f, "/* Type information for %s.\n", name);
-  for (i = 0; i < sizeof(hdr)/sizeof(hdr[0]); i++)
+  for (i = 0; i < ARRAY_SIZE (hdr); i++)
     oprintf (f, "%s", hdr[i]);
   return f;
 }
@@ -1626,8 +1626,7 @@ write_gc_root (f, v, type, name, has_len
 	  if (ap->u.a.len[0])
 	    oprintf (f, " * (%s)", ap->u.a.len);
 	  else if (ap == v->type)
-	    oprintf (f, " * (sizeof (%s) / sizeof (%s[0]))",
-		     v->name, v->name);
+	    oprintf (f, " * ARRAY_SIZE (%s)", v->name);
 	oprintf (f, ",\n");
 	oprintf (f, "    sizeof (%s", v->name);
 	for (ap = v->type; ap->kind == TYPE_ARRAY; ap = ap->u.a.p)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]