[LinuxBIOS] [PATCH] v3: Add ARRAY_SIZE macro

Stefan Reinauer stepan at coresystems.de
Fri Jun 29 16:48:30 CEST 2007


* Rudolf Marek <r.marek at assembler.cz> [070629 15:36]:
> Hi,
> 
> Just a short comment:
> 
> -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])		      \
> +	+ sizeof(typeof(int[1 - 2*!!__builtin_types_compatible_p(typeof(arr), \
> +		 typeof(&arr[0]))]))*0)
> 
> -- Rusty Russell <http://lwn.net/Articles/226010/>
> 
> Maybe we will need something more insane too?
 
I suggest we rather expect people to know what they are doing. Feeding a
non-array into a macro ARRAY_SIZE is not completely unlikely to happen
but adding trickery like the above will not make us any friends among
those trying to understand the code. 

-- 
coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
      Tel.: +49 761 7668825 • Fax: +49 761 7664613
Email: info at coresystems.dehttp://www.coresystems.de/




More information about the coreboot mailing list