Subject: Re: CVS commit: src/sys/lib/libkern
To: David Young <dyoung@netbsd.org>
From: David Laight <david@l8s.co.uk>
List: source-changes
Date: 03/28/2006 07:10:40
On Mon, Mar 27, 2006 at 09:18:33PM +0000, David Young wrote:
> 
> Module Name:	src
> Committed By:	dyoung
> Date:		Mon Mar 27 21:18:33 UTC 2006
> 
> Modified Files:
> 	src/sys/lib/libkern: libkern.h
> 
> Log Message:
> Per discussion on source-changes@, add __arraycount(array) for
> counting the number of elements in a static array, using the idiom,
> sizeof(array)/sizeof(array[0]).

How about casting the result to 'int' ?
The domain of the result will always fit in an int, whereas sizeof
will return a 64bit type on LP64 systems.
Using 'int' (not 'unsigned int') allows:
	int i;
	...
	for (i = 0; i < __arraycount(xxx); i++)
		...
work (without giving a 'signed v unsigned comparison' warning).

	David

-- 
David Laight: david@l8s.co.uk