WUtil: New macro 'wlengthof' in the public API to get number of elements in an array

The new macro 'wlengthof' returns the number of elements for which a local
array have been defined, which makes code easier to read than the
previous [sizeof() / sizeof([0]) ] construct.

The macro includes a static assertion to stop compilation if it is being
used on a pointer, for which we cannot know the size of the array, to
avoid generating dummy result. This can work only with C11 which
standardised the static assertions.

Signed-off-by: Christophe CURIS <christophe.curis@free.fr>
This commit is contained in:
Christophe CURIS authored and Carlos R. Mafra committed 2013-12-30 18:11:03 +00:00
1 parent c3a132215d
commit fd47650717
2 files changed
+32 -1

No files matched your search

+1 -1
View File
@@ -54,7 +54,7 @@ WINGS_VERSION=$WINGS_CURRENT:$WINGS_REVISION:$WINGS_AGE
AC_SUBST(WINGS_VERSION)
dnl
dnl libWUtil
WUTIL_CURRENT=3
WUTIL_CURRENT=4
WUTIL_REVISION=0
WUTIL_AGE=0
WUTIL_VERSION=$WUTIL_CURRENT:$WUTIL_REVISION:$WUTIL_AGE