All of lore.kernel.org
 help / color / mirror / Atom feed
* lots of code could be simplified by using ARRAY_SIZE()
@ 2006-12-13 19:58 Robert P. J. Day
       [not found] ` <2F8F687E-C5E5-4F7D-9585-97DA97AE1376@oracle.com>
                   ` (2 more replies)
  0 siblings, 3 replies; 18+ messages in thread
From: Robert P. J. Day @ 2006-12-13 19:58 UTC (permalink / raw)
  To: Linux kernel mailing list


  there are numerous places throughout the source tree that apparently
calculate the size of an array using the construct
"sizeof(fubar)/sizeof(fubar[0])". see for yourself:

  $ grep -Er "sizeof\((.*)\) ?/ ?sizeof\(\1\[0\]\)" *

but we already have, from "include/linux/kernel.h":

  #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))

a simple script to make the appropriate cleanup, given the directory
name as an argument:

================== cut ================
#!/bin/sh

DIR=$1

for f in $(grep -Erl "sizeof\((.*)\) ?/ ?sizeof\(\1\[0\]\)" ${DIR}) ;
do
  echo "Fixing $f ..."
  perl -pi -e "s|sizeof\((.*)\) ?/ ?sizeof\(\1\[0\]\)|ARRAY_SIZE\(\1\)|" $f
done
=======================================

  of course, the file must (eventually) include linux/kernel.h but one
would think that applies to the majority of the source tree, no?

  just a thought.

rday

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2006-12-17 18:30 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-13 19:58 lots of code could be simplified by using ARRAY_SIZE() Robert P. J. Day
     [not found] ` <2F8F687E-C5E5-4F7D-9585-97DA97AE1376@oracle.com>
2006-12-14 22:27   ` Robert P. J. Day
2006-12-14 23:13     ` Stefan Richter
2006-12-15 10:36       ` Jan Engelhardt
2006-12-15 20:48         ` Robert P. J. Day
2006-12-15 22:54           ` Tim Schmielau
2006-12-16 11:59             ` Robert P. J. Day
2006-12-16 13:30               ` Tim Schmielau
2006-12-16 13:55                 ` Robert P. J. Day
2006-12-17 18:13             ` Robert P. J. Day
2006-12-17 18:27               ` Randy Dunlap
2006-12-17 18:25                 ` Robert P. J. Day
2006-12-14 23:16 ` Miguel Ojeda
2006-12-15  0:12   ` Robert P. J. Day
2006-12-16  8:40 ` Pavel Machek
2006-12-16 13:09   ` Robert P. J. Day
2006-12-16 18:14     ` Jan Engelhardt
2006-12-17 11:44       ` Stefan Richter

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.