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

2014-04-23 Thread Rob
Martti Kühne, 22 April 2014 : > On Sun, Apr 20, 2014 at 9:24 PM, Rob wrote: >> Into the bikeshed I go... >> >> LEN(a + 2) doesn't mean anything anyway, as a's type decays. >> >> To do it properly there should be some kind of static assert in the >> macro that the argument is of array type. But thi

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

2014-04-22 Thread Martti Kühne
On Sun, Apr 20, 2014 at 9:24 PM, Rob wrote: > Into the bikeshed I go... > > LEN(a + 2) doesn't mean anything anyway, as a's type decays. > > To do it properly there should be some kind of static assert in the > macro that the argument is of array type. But this is a small code base > and you'd exp

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

2014-04-20 Thread Rob
On 20/04/14, sin wrote: On Sun, Apr 20, 2014 at 02:43:53PM +0200, FRIGN wrote: On Sun, 20 Apr 2014 13:53:33 +0200 #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[] =

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

2014-04-20 Thread FRIGN
On Sun, 20 Apr 2014 20:13:02 +0100 sin wrote: > 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)); Ah, that's right! Thanks for noting this. Cheers FRIGN -- FRIGN

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

2014-04-20 Thread sin
On Sun, Apr 20, 2014 at 02:43:53PM +0200, FRIGN wrote: > On Sun, 20 Apr 2014 13:53:33 +0200 > Alexander Huemer wrote: > > > > […] > > > -#define LEN(a) (sizeof(a) / sizeof(a[0])) > > > +#define LEN(a) (sizeof(a) / sizeof(a)[0]) > > > […] > > > > Why parenthesis anyway? a[0] is an express

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

2014-04-20 Thread sin
On Sun, Apr 20, 2014 at 08:58:23PM +0200, Roberto E. Vargas Caballero wrote: > > #define LEN(x) (sizeof (x) / sizeof *(x)) > > I am used to read the other form, but I thing it is only a question > of personal taste, and since the other form was sent before your suggestion > I'll apply it. Yes, pe

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

2014-04-20 Thread Roberto E. Vargas Caballero
> #define LEN(x) (sizeof (x) / sizeof *(x)) I am used to read the other form, but I thing it is only a question of personal taste, and since the other form was sent before your suggestion I'll apply it. Regards, -- Roberto E. Vargas Caballero

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

2014-04-20 Thread sin
On Sun, Apr 20, 2014 at 04:07:12PM +0400, non...@inventati.org wrote: > On Sun, Apr 20, 2014 at 01:53:33PM +0200, Alexander Huemer wrote: > > Hi, > > > > On Sun, Apr 20, 2014 at 03:41:40PM +0400, non...@inventati.org wrote: > > > […] > > > -#define LEN(a) (sizeof(a) / sizeof(a[0])) > > > +#def

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

2014-04-20 Thread Balazs Kezes
On 2014-04-20 14:43 +0200, FRIGN wrote: > However, I don't see any error in the way it was done before noname > suggested changing it. It's a common practice in C macros to enclose each argument instance with parentheses to avoid most pitfalls. This particular case will most probably be fine witho

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

2014-04-20 Thread FRIGN
On Sun, Apr 20, 2014 at 03:41:40PM +0400 non...@inventati.org wrote: > […] > -#define LEN(a) (sizeof(a) / sizeof(a[0])) > +#define LEN(a) (sizeof(a) / sizeof(a)[0]) > […] Btw: 1) Use git format-patch instead of generating normal diffs 2) Don't just send your diffs in without saying anythi

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

2014-04-20 Thread FRIGN
On Sun, 20 Apr 2014 13:53:33 +0200 Alexander Huemer 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 f

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

2014-04-20 Thread noname
On Sun, Apr 20, 2014 at 01:53:33PM +0200, Alexander Huemer wrote: > Hi, > > On Sun, Apr 20, 2014 at 03:41:40PM +0400, non...@inventati.org wrote: > > […] > > -#define LEN(a) (sizeof(a) / sizeof(a[0])) > > +#define LEN(a) (sizeof(a) / sizeof(a)[0]) > > […] > > Why parenthesis anyway? a[0]

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

2014-04-20 Thread Alexander Huemer
Hi, On Sun, Apr 20, 2014 at 03:41:40PM +0400, non...@inventati.org 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 f

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

2014-04-20 Thread noname
diff --git a/st.c b/st.c index df660ff..fbbdc34 100644 --- a/st.c +++ b/st.c @@ -68,7 +68,7 @@ char *argv0; #define SERRNO strerror(errno) #define MIN(a, b) ((a) < (b) ? (a) : (b)) #define MAX(a, b) ((a) < (b) ? (b) : (a)) -#define LEN(a) (sizeof(a) / sizeof(a[0])) +#define LEN(a) (si