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
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
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[] =
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
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
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
> #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
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
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
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
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
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]
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
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
14 matches
Mail list logo