Can,t make a pointer to a const array.

cancel
Showing results for 
Search instead for 
Did you mean: 

Can,t make a pointer to a const array.

Jump to solution
570 Views
perhojfeldt
Contributor III

Having problem with assign a unsigned char const array to a pointer. Works fine to assign an unsigned char array to a pointer.

What do I wrong. Using Codewarrior version 11.0 with MCU MC9S08QD4. Attached is a little project that illustrate the problem. I have tried to cast the array to unsigned char far but little did it help.

Sincerly Yours

Per Højfeldt

DSC_0013.JPG

Labels (1)
1 Solution
378 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Per,

Your project use Tiny memory model.

With Tiny model, By default all variables are in the zero page (direct memory access). Variables outside the zero page can be used with pragmas or the far keyword.

To fix this error, one easy solution is to create a new project with Small memory model, then input your code to main file. You will see your project can pass build.

pastedImage_1.png

I have verified it from my side.

If you still can't fix it by yourself, please just let me know.


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

6 Replies
379 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Per,

Your project use Tiny memory model.

With Tiny model, By default all variables are in the zero page (direct memory access). Variables outside the zero page can be used with pragmas or the far keyword.

To fix this error, one easy solution is to create a new project with Small memory model, then input your code to main file. You will see your project can pass build.

pastedImage_1.png

I have verified it from my side.

If you still can't fix it by yourself, please just let me know.


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

378 Views
perhojfeldt
Contributor III

Hi  Jennie,

I tried to make a model in Small instead of Tiny and the error went away. But still come up with an warning. Unsigned char const -> unsigned char. I change the unsigned char pointer to a far pointer and the warning went away. Why? Is a pointer not always an integer in an MCU with 16bit memory? I also change the project.prm file so the ram area is from 0x0060 to 0x015F. Ram area was also tried as 0x0100 to 0x015F but same warning.

Like You said if I use far in Tiny model does warnings and errors away. Looks like that the way.

Thanks for Your help.

Sincerly Yours

Per Højfeldt

0 Kudos
378 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hello Per,

This error is because there are two pointers in the statement pointing to non-equal types.

in your code,

pb is defined as unsigned char *

b is defined as const unsigned char *

these two type are not match. 

casting const to pb can solve the problem:

change

unsigned char *pb;

to

const unsigned char *pb;


Have a great day,
TIC

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
378 Views
perhojfeldt
Contributor III

Hi Jennie,

Funny though. If you change the unsigned char *pb to unsigned char *far pb the warning disapear. Still the pointers are of none equal types. Well got it to work fine in Tiny model just by changing pointer from unsigned char * to unsigned char *far. A little to think about.

Take care.

Per

0 Kudos
378 Views
perhojfeldt
Contributor III

Hi again,

The pointer should be able to handle both const unsigned char arrays in flash for programing and struct in RAM. It works fine by define the pointer as

unsigned char *far ucpPtr. No errors no warnings. All good.

Per

0 Kudos
378 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

If use tiny mode, if variables outside the zero page(8bits address) , we have to use pragma or far key words to get over this limit.

I know use "far" is also an option, but you need do it for every variable that is over 8bit address.

If your memory space is enough for your code, the advantage of  using small mode is that it is easier for programming.

0 Kudos