On Wednesday, 2017-05-10 17:25:04 +0200, Jan Engelhardt wrote:
> 
> On Wednesday 2017-05-10 17:20, Dima Ryazanov wrote:
> >      +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])
> >
> >
> >I'm guessing this works, but "sizeof(a)[0]" looks very unintuitive to me. I 
> >think "sizeof(a[0])" is
> >the convention?
> 
> If going with the sizeof(T) syntax, then the answer would 
> be "sizeof((a)[0])", or alternatively, "sizeof(*(a))".

The syntax [1] is `sizeof(T)` for a type, and `sizeof E` for an
expression, which the array variable passed in is.
Since it's in a macro, you have to put brackets around arguments,
hence the `(a)` in both cases.

I can add unnecessary brackets if you want, but that would be purely
cosmetic, no actual machine purpose ;)

[1] http://en.cppreference.com/w/c/language/sizeof
_______________________________________________
wayland-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/wayland-devel

Reply via email to