Subject: Re: CVS commit: src/sys/lib/libkern
To: None <source-changes@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: source-changes
Date: 03/28/2006 18:07:18
In article <20060328061040.GU29748@snowdrop.l8s.co.uk>,
David Laight  <david@l8s.co.uk> wrote:
>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).
>

This is wrong given that the number is unsigned. Although it fits in
an int, it does not make it signed. You should be converting your
loops to use u_int or size_t instead.

christos