public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "H. Peter Anvin" <hpa@zytor.com>
To: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] hex <-> int conversion routines.
Date: 19 Feb 2002 12:27:28 -0800	[thread overview]
Message-ID: <a4ucfg$tfa$1@cesium.transmeta.com> (raw)
In-Reply-To: <02021919493204.00447@jakob> <200202191902.g1JJ2wx28246@frodo.gams.co.at>

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>

  reply	other threads:[~2002-02-19 20:28 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-19 15:39 [PATCH] hex <-> int conversion routines Jakob Kemi
2002-02-19 15:52 ` Martin Dalecki
2002-02-19 18:49   ` Jakob Kemi
2002-02-19 19:02     ` Bernd Petrovitsch
2002-02-19 20:27       ` H. Peter Anvin [this message]
2002-02-23  2:30         ` Ian Molton
2002-02-19 19:04     ` H. Peter Anvin
2002-02-20 10:25     ` Martin Dalecki
2002-02-19 16:51 ` Richard B. Johnson
2002-02-19 18:02 ` Linus Torvalds
2002-02-19 20:29   ` george anzinger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='a4ucfg$tfa$1@cesium.transmeta.com' \
    --to=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox