2 Oct
2017
2 Oct
'17
6:16 a.m.
On Sun, 2017-10-01 at 15:30 -0400, Jérémy Lefaure wrote:
Using the ARRAY_SIZE macro improves the readability of the code.
Found with Coccinelle with the following semantic patch: @r depends on (org || report)@ type T; T[] E; position p; @@ ( (sizeof(E)@p /sizeof(*E))
(sizeof(E)@p /sizeof(E[...]))
(sizeof(E)@p /sizeof(T)) )
[]
diff --git a/sound/oss/ad1848.c b/sound/oss/ad1848.c
[]
@@ -797,7 +798,7 @@ static int ad1848_set_speed(int dev, int arg)
int i, n, selected = -1;
- n = sizeof(speed_table) / sizeof(speed_struct);
- n = ARRAY_SIZE(speed_table);
These sorts of changes are OK, but for many uses, it's more readable to use ARRAY_SIZE(foo) in each location rather than using a temporary.