linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tim Walberg <twalberg@comcast.net>
To: Michal Nazarewicz <mina86@tlen.pl>
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 09:30:08 -0600	[thread overview]
Message-ID: <20101220153008.GH16355@comcast.net> (raw)
In-Reply-To: <87aak0tsf3.fsf@erwin.mina86.com>

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...



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--


End of included message



-- 
+----------------------+
| Tim Walberg          |
| 830 Carriage Dr.     |
| Algonquin, IL 60102  |
| twalberg@comcast.net |
+----------------------+

  reply	other threads:[~2010-12-20 15:30 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 [this message]
2010-12-20 15:40     ` Michal Nazarewicz
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=20101220153008.GH16355@comcast.net \
    --to=twalberg@comcast.net \
    --cc=linux-c-programming@vger.kernel.org \
    --cc=mina86@tlen.pl \
    --cc=ratheesh.ksz@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).