Skip to content
Commit c2d38ec2 authored by Nicolas Pitre's avatar Nicolas Pitre Committed by Anas Nashif
Browse files

ARRAY_SIZE(): make it usable on 64-bit systems



With code that looks like this:

	for (int i = ARRAY_SIZfoo) - 1; i >= 0; i--) ...

If foo is empty, ARRAY_SIZfoo) will return 0. But since it is
implemented using an unsigned long, the answer to 0UL - 1 is
18446744073709551615 on a 64-bit system, and that doesn't fit into
an int. The compiler complains with:

warning: overflow in conversion from ‘long unsigned int’ to ‘int’ changes value from ‘18446744073709551615’ to ‘-1’ [-Woverflow]

Let's fix that and get the expected behavior simply by turning the
unsigned long into a signed long.

Signed-off-by: default avatarNicolas Pitre <npitre@baylibre.com>
parent a04a2ca7
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment