lkml.org 
[lkml]   [2002]   [Feb]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH] hex <-> int conversion routines.
Date
Followup to:  <200202191902.g1JJ2wx28246@frodo.gams.co.at>
By author: Bernd Petrovitsch <bernd@gams.at>
In newsgroup: linux.dev.kernel
>
> 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";
>

Better yet...

extern const char inthex_digits[];
static __inline__ char inthex_nybble(int x)
{
return inthex_digits[x & 15];
}

(Nibble = small amount of food; nybble = 4 bits. It's a pun on
bite/byte.)

-hpa

--
<hpa@transmeta.com> at work, <hpa@zytor.com> in private!
"Unix gives you enough rope to shoot yourself in the foot."
http://www.zytor.com/~hpa/puzzle.txt <amsp@zytor.com>
-
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/

\
 
 \ /
  Last update: 2005-03-22 13:24    [W:0.058 / U:1.176 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site