Re: Accessing members of array as a different type
Jens.Toerring_at_physik.fu-berlin.de
Date: 09/16/04
- Previous message: Paul Hsieh: "Re: Loop Optimization, Array Alignment"
- In reply to: James A: "Accessing members of array as a different type"
- Next in thread: Mike Wahler: "Re: Accessing members of array as a different type"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 16 Sep 2004 19:19:02 GMT
James A <me@privacy.net> wrote:
> I'm having trouble geting my head around this, although I know it's a pretty
> basic question.
> I have an application whereby an area of RAM is mapped to an array:
> unsigned char NV[128];
> Two consequtive elements are used to hold an unsigned int (2 bytes on this
> platform). How do I access it as an unsigned int?
> e.g.
> unsigned int test;
> ...
> test = *(unsigned int *)(&(NV[15]);
> In this case, I'm trying to retrieve the unsigned int value represented by
> elements 15 & 16 of the array. It does not seem to be working.
It would be helpful to tell what you mean by "not seem to be working".
That construct could, for example, crash your program with a SIGBUS
error because of an unaligned access. Or it could work but deliver
an unexpected result. But what you expect is something that no-one
can figure out from what you write, so it could be that the numbers
you're expecting in memory are stored in big-endian order while you
try to do all of that on a little endian machine etc. Or it could
be because what you try to read belongs actually to two different
2-byte numbers (if, as you write, all the 128 bytes are occupied
by 64 2-byte numbers).
Regards, Jens
-- \ Jens Thoms Toerring ___ Jens.Toerring@physik.fu-berlin.de \__________________________ http://www.toerring.de
- Previous message: Paul Hsieh: "Re: Loop Optimization, Array Alignment"
- In reply to: James A: "Accessing members of array as a different type"
- Next in thread: Mike Wahler: "Re: Accessing members of array as a different type"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|