[PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

Eric Engestrom eric.engestrom at imgtec.com
Wed May 10 17:06:08 UTC 2017


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


More information about the wayland-devel mailing list