Re: [dev] [st] [patch] misplaced parenthesis in LEN macro

From: FRIGN <dev_AT_frign.de>
Date: Sun, 20 Apr 2014 14:43:53 +0200

On Sun, 20 Apr 2014 13:53:33 +0200
Alexander Huemer <alexander.huemer_AT_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.
The length of an array is the size of the array divided by the length
of each element's type.
However, I don't see any error in the way it was done before noname
suggested changing it.

Cheers

FRIGN

-- 
FRIGN <dev_AT_frign.de>
Received on Sun Apr 20 2014 - 14:43:53 CEST

This archive was generated by hypermail 2.3.0 : Sun Apr 20 2014 - 14:48:06 CEST