Source-Changes archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: CVS commit: src/sys/lib/libkern
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@localhost
Home |
Main Index |
Thread Index |
Old Index