Re: [PATCH] hex <-> int conversion routines.

Bernd Petrovitsch (bernd@gams.at)
Tue, 19 Feb 2002 20:02:57 +0100


Jakob Kemi <jakob.kemi@telia.com> wrote:
>> > +static __inline__ char inthex_nibble(int x)
>> > +{
>> > + const char* digits = "0123456789abcdef";
>> > +
>> > + return digits[x & 0x0f];
>> > +}
>>
>> perhaps better do static const char *digits.
>GCC doesn't copy const strings, as opposed to other const arrays.
>So it should be fine as it is. GCC also reuse duplicated strings.

You could also do
return "0123456789abcdef"[x & 0x0f];
though some will find it bad, ugly, wrong
or make a file-global
static const char digits[] = "0123456789abcdef";

Bernd

-- 
Bernd Petrovitsch                              Email : bernd@gams.at
g.a.m.s gmbh                                  Fax : +43 1 205255-900
Prinz-Eugen-Straße 8                    A-1040 Vienna/Austria/Europe
                     LUGA : http://www.luga.at

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/