All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Nazarewicz <mina86@tlen.pl>
To: Tim Walberg <twalberg@comcast.net>
Cc: ratheesh k <ratheesh.ksz@gmail.com>, linux-c-programming@vger.kernel.org
Subject: Re: union to get parts of integer
Date: Mon, 20 Dec 2010 16:40:14 +0100	[thread overview]
Message-ID: <8762uotpup.fsf@erwin.mina86.com> (raw)
In-Reply-To: <20101220153008.GH16355@comcast.net> (Tim Walberg's message of "Mon, 20 Dec 2010 09:30:08 -0600")

Tim Walberg <twalberg@comcast.net> writes:
> It's likely that either the union or direct pointer expressions yield
> more efficient code, as they can probably be compiled to direct byte-width
> load/store instructions, rather than shifts and logical ands... However,
> if the code's not in a critical path for performance, it probably won't
> matter. And on some architectures, there may not be byte-width operations,
> I guess...

It's not the issue of performance.  It's an issue of whether you want
each separate byte as saved in memory (which should rarely be the case)
or if you want specific part of the value.

> On 12/20/2010 15:44 +0100, Michal Nazarewicz wrote:
>>>	
>>>	((char *)&i)[0].
>>>	
>>>	However, are you sure that you need this?  Don't you need "(i & 255)",
>>>	"((i >> 8) & 255)", etc. instead?
>>>	
>>>	-- 
>>>	Best regards,                                         _     _
>>>	 .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
>>>	 ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
>>>	 ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--

-- 
Best regards,                                         _     _
 .o. | Liege of Serenly Enlightened Majesty of      o' \,=./ `o
 ..o | Computer Science,  Michal "mina86" Nazarewicz   (o o)
 ooo +--<mina86-tlen.pl>--<jid:mina86-jabber.org>--ooO--(_)--Ooo--

  reply	other threads:[~2010-12-20 15:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-20 10:40 union to get parts of integer ratheesh k
2010-12-20 12:03 ` Reza Hoorfar
2010-12-20 14:44 ` Michal Nazarewicz
2010-12-20 15:30   ` Tim Walberg
2010-12-20 15:40     ` Michal Nazarewicz [this message]
2010-12-21 16:22     ` Glynn Clements

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=8762uotpup.fsf@erwin.mina86.com \
    --to=mina86@tlen.pl \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=ratheesh.ksz@gmail.com \
    --cc=twalberg@comcast.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.