From: etmax on
I've created an array of bitmaps for an LCD display (6 bytes per character)
and when I tried to define an array of addresses of the bitmap arrays Code
composer allocated them in RAM even though I said they were const, so I
cast them as an array of ints.

I had planned to get a pointer to the first address then use array
terminology to get the address of the bit map for the current char but I
keep on getting a char not an int back.

Can anyone tell me where I went wrong please

const uint Chars0[] = { (uint)&Data0020,(uint)&Data0020,(uint)&Data0020};

uchar *CharPtr;

CharPtr = (uchar *)&Chars0 //this works ok (points to the first element)

CharPtr = (uchar*)((uint)CharPtr[Char]); // this puts in only one byte of
the address??

What am I doing wrong?




---------------------------------------
Posted through http://www.EmbeddedRelated.com
From: Jack on
On 9 Ago, 14:52, "etmax" <max(a)n_o_s_p_a_m.einstein-tech.com.au> wrote:
> I've created an array of bitmaps for an LCD display (6 bytes per character)
> and when I tried to define an array of addresses of the bitmap arrays Code
> composer allocated them in RAM even though I said they were const, so I
> cast them as an array of ints.

you probably need to chage something in the linker file (or whatever
name your IDE use for the file the linker use to know where to put,
variables,const,literals,...)

> I had planned to get a pointer to the first address then use array
> terminology to get the address of the bit map for the current char but I
> keep on getting a char not an int back.
>
> Can anyone tell me where I went wrong please
>
> const uint Chars0[] = { (uint)&Data0020,(uint)&Data0020,(uint)&Data0020};

not sure why you cast the address to Data0020 to uint? Why do not
create directly an array of pointers?

> uchar *CharPtr;

why do you declare CharPtr as uchar* and not as uint* ? A pointer to a
uint should be a uint*, not a uchar*.

> CharPtr = (uchar *)&Chars0 //this works ok (points to the first element)

Chars0 is already a pointer, so & is wrong. Either you use &Chars0[0]
or Chars0 to get the address of the first element of Chars0.

>
> What am I doing wrong?

Some bad casting I suppose

Bye Jack


From: WangoTango on
In article <atudnZcl8OVqZMLRnZ2dnUVZ_vmdnZ2d(a)giganews.com>,
max(a)n_o_s_p_a_m.einstein-tech.com.au says...
> I've created an array of bitmaps for an LCD display (6 bytes per character)
> and when I tried to define an array of addresses of the bitmap arrays Code
> composer allocated them in RAM even though I said they were const, so I
> cast them as an array of ints.
>
> I had planned to get a pointer to the first address then use array
> terminology to get the address of the bit map for the current char but I
> keep on getting a char not an int back.
>
> Can anyone tell me where I went wrong please
>
> const uint Chars0[] = { (uint)&Data0020,(uint)&Data0020,(uint)&Data0020};
>
> uchar *CharPtr;
>
> CharPtr = (uchar *)&Chars0 //this works ok (points to the first element)
Isn't this mixing indirection?
Shouldn't you choose between :
CharPtr = (uchar *)&Char0[0]
or
CharPtr = (uchar *)Char0

and why are you casting the array elements to an unsigned int from and
address?

Or am I getting myself messed up here, or not understanding what you are
doing, wouldn't be the first time.

>
> CharPtr = (uchar*)((uint)CharPtr[Char]); // this puts in only one byte of
> the address??
>
> What am I doing wrong?

From: Robert Adsett on
On Aug 9, 9:49 am, Jack <jack4...(a)gmail.com> wrote:
> On 9 Ago, 14:52, "etmax" <max(a)n_o_s_p_a_m.einstein-tech.com.au> wrote:
> > CharPtr = (uchar *)&Chars0 //this works ok (points to the first element)
>
> Chars0 is already a pointer, so & is wrong. Either you use &Chars0[0]
> or Chars0 to get the address of the first element of Chars0.

Not wrong exactly. A little obscure maybe.

The expression &Chars0 is a pointer to an array as, IIRC is Chars0.
&Chars0[0] is a pointer to the first element of the array. So all
three expressions end up with the same value just not all the same
type.

Personally I'd make the pointer array a void pointer array rather that
unsigned int to avoid all the extra casts. It's not as if you are
getting any extra type safety anyway.

But I don't understand "this puts in only one byte of the address?? "

This to me suggests there may be some target specific chicanery(1)
going on and since we don't know what the target is....

Robert

1- IE like const pointers and non const pointers having different
address spaces.
From: Robert Adsett on
On Aug 9, 11:14 am, Robert Adsett <s...(a)aeolusdevelopment.com> wrote:
> On Aug 9, 9:49 am, Jack <jack4...(a)gmail.com> wrote:
>
> > On 9 Ago, 14:52, "etmax" <max(a)n_o_s_p_a_m.einstein-tech.com.au> wrote:
> > > CharPtr = (uchar *)&Chars0 //this works ok (points to the first element)
>
> > Chars0 is already a pointer, so & is wrong. Either you use &Chars0[0]
> > or Chars0 to get the address of the first element of Chars0.
>
> Not wrong exactly.  A little obscure maybe.
>
> The expression &Chars0 is a pointer to an array as, IIRC is Chars0.

Ugg, memory clears up a little

&Chars0 type pointer to array
Chars0 type array (which devolves to a pointer to array in context)

I think that's closer to accurate. Someone with a working knowledge
of the appropriate standards probably can provide the proper
definitions.

Robert