Subject: kern/10366: there is no 'how many elements' macro in the kernel.
To: None <>
From: None <>
List: netbsd-bugs
Date: 06/14/2000 12:05:26
>Number:         10366
>Category:       kern
>Synopsis:       there is no 'how many elements' macro in the kernel.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 14 12:06:00 PDT 2000
>Originator:     Chris Demetriou
>Release:        NetBSD-current as of today (20000614)
The kernel headers (most notably sys/param.h) define lots of
convenience macros, e.g. howmany(), powerof2(), etc. for kernel

One which is notably missing is a 'how many array elements' macro,
which implemented something like:

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

where 'x' is a statically-initialized array, and the value 
is the number of elements in that array.

there's a bunch of kernel code which does things like:

	const struct foo bar[] = { ... many entries ... };
	const int bar_size = sizeof bar / sizeof bar[0];

this is wasteful, and error-prone.


Pick a name, and commit it.  I'd have done that myself, if any two
people could agree on a name, but don't have time to spend to gather
that consensus.

my personal favorite name, btw, is howmanyelems() (a la howmany()).