On Sun, Apr 20, 2014 at 02:43:53PM +0200, FRIGN wrote: > On Sun, 20 Apr 2014 13:53:33 +0200 > Alexander Huemer <alexander.hue...@xx.vu> wrote: > > > > […] > > > -#define LEN(a) (sizeof(a) / sizeof(a[0])) > > > +#define LEN(a) (sizeof(a) / sizeof(a)[0]) > > > […] > > > > Why parenthesis anyway? a[0] is an expression, not a type, and there is > > nothing to group here. sizeof is not a function! > > #define LEN(a) (sizeof a / sizeof *a) > > is the right way to do it.
You are missing the parentheses there. Your macro provides the wrong answer for something like: int a[] = { 1, 2, 3, 4, 5 }; printf("%zu\n", LEN(a + 2)); Cheers, sin