Re: Strangeness when moving data through an array.
Re: Strangeness when moving data through an array.
- Subject: Re: Strangeness when moving data through an array.
- From: Sherm Pendley <email@hidden>
- Date: Wed, 1 Dec 2004 06:43:25 -0500
On Dec 1, 2004, at 6:13 AM, Jeff Laing wrote:
Not on architectures that care about word-alignment you don't.
Sorry, I didn't mean to imply that direct assignment was a good idea. I
was simply pointing out that, if you wanted to use direct assignment,
the simple form wouldn't do - the typecasting and dereferencing would
be needed.
You're right though - I should have included a caveat.
If pkt[MSEQ] is not on a 16-bit boundary, you'll get an exception.
I'd figure it would take a few extra cycles to access across word
boundaries, but an exception? That's harsh.
For myself, assuming I knew the data in the buffer is big-endian, I'd
use a little arithmetic to avoid both word-alignment and host-endian
issues:
short_test = pkt[MSEQ]*256 + pkt[MSEQ+1];
This assumes, of course, that pkt[] is an array of one-byte types such
as char, so that the pointer arithmetic works as expected.
sherm--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden