Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Fre, 2012-09-14 at 16:25 +0200, Jan Engelhardt wrote: > On Friday 2012-09-14 15:46, Jim Rees wrote: > >Jan Engelhardt wrote: > > >A pure K&R-C version would use a string: > > >#define base10len(i) > > "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > > >(if I converted them properly i

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 15:46, Jim Rees wrote: >Jan Engelhardt wrote: > > >A pure K&R-C version would use a string: > >#define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > >(if I converted them properly into hexadecimal) > The syntax is \x01\x03\x05... > >K&R doesn't have

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Jan Engelhardt wrote: Your way does not function as originally desired. * base10len(i) no longer expands to a compile-time constant * you will definitely have a variable base10len_vals in your objects, so you waste a read operation whenever it is used. No, I meant my original w

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Bernd Petrovitsch wrote: [] > Pure K&R: We can (and should) make it "const" too. No "const" in K&R either. But I think we can assume the kernel will be compiled with something a bit more advance. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Jan Engelhardt wrote: >A pure K&R-C version would use a string: >#define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] >(if I converted them properly into hexadecimal) The syntax is \x01\x03\x05... K&R doesn't have the \x escape, only \0 (octal). -- To unsubscribe fr

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 14:30, Jim Rees wrote in an odd quote style (the > are mine): >Bernd Petrovitsch wrote: > > A pure K&R-C version would use a string: > snip > #define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > snip > (if I converted them p

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Fre, 2012-09-14 at 08:30 -0400, Jim Rees wrote: > Bernd Petrovitsch wrote: [...] > A pure K&R-C version would use a string: > snip > #define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x14"[sizeof(i)] > snip > (if I converted them properly into hexadecim

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread J. Bruce Fields
On Fri, Sep 14, 2012 at 08:30:14AM -0400, Jim Rees wrote: > But I still like my way better. Yeah. It looks less mysterious once you realize it's just a straightforward application of the usual coincidence 2^10 = 1024 ~ 1000 = 10^3 How about this? Also with some more defines because I l

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jan Engelhardt
On Friday 2012-09-14 11:17, Bernd Petrovitsch wrote: >Shouldn't that have been > snip >#define base10len(i) ((const int[]){1,3,5,8,10,13,15,17,20}[sizeof(i)]) > snip Yeah. >A pure K&R-C version would use a string: >#define base10len(i) "\0x1\0x3\0x5\0x8\0x0A\0x0D\0x0F\0x11\0x1

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Jim Rees
Bernd Petrovitsch wrote: On Mon, 2012-09-10 at 08:19 +0200, Jan Engelhardt wrote: > On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: [...] > >+/* > >+ * length of the decimal representation of an unsigned integer. Just an > >+ * approximation, but it's right for types of size 1 to

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-14 Thread Bernd Petrovitsch
On Mon, 2012-09-10 at 08:19 +0200, Jan Engelhardt wrote: > On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: [...] > >+/* > >+ * length of the decimal representation of an unsigned integer. Just an > >+ * approximation, but it's right for types of size 1 to 36 bytes: > >+ */ > >+#define base10le

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-09-09 Thread Jan Engelhardt
On Tuesday 2012-08-21 23:29, J. Bruce Fields wrote: >I've seen a couple examples recently where we've gotten this wrong. >Maybe something like this would help? Is there some better way? >(Approximation due to Jim Rees). > >+/* >+ * length of the decimal representation of an unsigned integer. Jus

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Jim Rees
Al Viro wrote: On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: > J. Bruce Fields wrote: > > From: "J. Bruce Fields" > > I've seen a couple examples recently where we've gotten this wrong. > Maybe something like this would help? Is there some better way? >

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread J. Bruce Fields
On Tue, Aug 21, 2012 at 11:06:13PM +0100, Al Viro wrote: > On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: > > J. Bruce Fields wrote: > > > > From: "J. Bruce Fields" > > > > I've seen a couple examples recently where we've gotten this wrong. > > Maybe something like this would

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Al Viro
On Tue, Aug 21, 2012 at 05:22:27PM -0400, Jim Rees wrote: > J. Bruce Fields wrote: > > From: "J. Bruce Fields" > > I've seen a couple examples recently where we've gotten this wrong. > Maybe something like this would help? Is there some better way? > > (Approximation due to Jim Ree

Re: [PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread Jim Rees
J. Bruce Fields wrote: From: "J. Bruce Fields" I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). Please add Suggested-by: Jim Rees . I'm thinking of patenting the al

[PATCH] strings: helper for maximum decimal encoding of an unsigned integer

2012-08-21 Thread J. Bruce Fields
From: "J. Bruce Fields" I've seen a couple examples recently where we've gotten this wrong. Maybe something like this would help? Is there some better way? (Approximation due to Jim Rees). Signed-off-by: J. Bruce Fields --- include/linux/string.h |6 ++ net/sunrpc/cache.c |2