pointers, damned pointers

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

formatting link

Reply to
etmax
Loading thread data ...

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

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

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

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.

Some bad casting I suppose

Bye Jack

Reply to
Jack

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.

Reply to
WangoTango

nt)

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.
Reply to
Robert Adsett

Why do you think "const" should change where the pointers are stored? If you need them to be in a particular segment you need to put them there explicitly.

Your data is integer but you're addressing it as char.

This line makes no sense at all - it's trying to load the first byte of character data as a pointer. I'm pretty sure that's not want you wanted. I think you want something like:

const uint Chars0[] = { ... } uint *CharPtr = &Chars0 uint data = CharPtr[index]; // where index is 0..2

Even better would be to define a struct for the character data even though the data is just an integer array. That way, the compiler will do the math for you when you index in the array of characters.

typedef struct { int data[3]; } Character; Character Font[] = { { ... }, { (uint)&Data0020,(uint)&Data0020,(uint)&Data0020 }, { ... } }; uint data = Font[ /* 0..numChars */ ].data[ /* 0..2 */ ];

And try not to use variables with names like "Char" ... it's too easy to mistype them and get errors from the compiler. I know this is difficult when you're playing with fonts because the logical names to use are variations on "character". But don't do it.

George

Reply to
George Neuner

You are barking up the wrong tree, so to say. You are talking to the compiler, but the compiler doesn't decide in what sections data go. That is the task of a program, that is called linker, linking loader or sometimes loader. So you have to summon up the linker and tell it your wishes. This can be complicated in a IDE, that does everything automatically.

Put this data in a separate file and generate a separate object file. Then tell the linker, via link file, link configuration, linker script, makefile or some such that you want it in ROM. This depends on your IDE and only people with experience with your exact IDE can give more details.

I wouldn't call it wrong. You're missing an insight that IDE's try to hide it from you.

Groetjes Albert

--

--
Albert van der Horst, UTRECHT,THE NETHERLANDS
Economic growth -- being exponential -- ultimately falters.
albert@spe&ar&c.xs4all.nl &=n http://home.hccnet.nl/a.w.m.van.der.horst
Reply to
Albert van der Horst

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.