1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-31 14:50:15 +03:00

basic: make sure argument of ELEMENTSOF is an array

Using ELEMENTSOF on a pointer will result in a compilation error.
This commit is contained in:
Michal Schmidt 2015-09-14 20:32:17 +02:00
parent ac2896bab6
commit 7f39a21045

View File

@ -123,8 +123,11 @@ static inline unsigned long ALIGN_POWER2(unsigned long u) {
return 1UL << (sizeof(u) * 8 - __builtin_clzl(u - 1UL));
}
#define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
#define ELEMENTSOF(x) \
__extension__ (__builtin_choose_expr( \
!__builtin_types_compatible_p(typeof(x), typeof(&*(x))), \
sizeof(x)/sizeof((x)[0]), \
(void)0))
/*
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.