Skip to content
Commit 1209245b authored by Leandro Pereira's avatar Leandro Pereira Committed by Jukka Rissanen
Browse files

util: Ensure ARRAY_SIZE() will only take arrays

This code is inspired by a similar feature found in ccan[1],
that enforces that the parameter passed to ARRAY_SIZE() is
always an array and not a generic pointer.  This is a slightly modified
version that will work if the macro is expanded outside of a function
body.

The check is performed by comparing if typeof(array) and
typeof(&array[0]) are of a different type.  Due to the way arrays
decays to pointers in C, if one passes a pointer, the types won't be
compatible and a compile time assertion will fail.

No bugs have been found with this change, but since there's no runtime
or size overheads, there's no reason to not enable it.

[1] https://github.com/rustyrussell/ccan/blob/master/ccan/array_size/\


    array_size.h

Change-Id: I6c321714d0024298e593176be43b2d0b5362cc0d
Signed-off-by: default avatarLeandro Pereira <leandro.pereira@intel.com>
parent 1223c2b6
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment