X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fbasic%2Fmacro.h;h=e93d7f155273a8a8618eaed8df429a03b88bbcfe;hp=b9a24f639ac45b71982fe3a0aac90c2be8e9b36d;hb=9f8b2124694ac1637198d9a336e2c97e79fd8c23;hpb=daba0b92bcc7f7541aa7984c4b5ea48748bb46c3 diff --git a/src/basic/macro.h b/src/basic/macro.h index b9a24f639..e93d7f155 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -124,8 +124,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.