const unsigned char * is incompatible with unsigned char *

10 Jul 2011

Hello, I get the error message : const unsigned char * is incompatible with parameter of type unsigned char * Why ? The const operator only tell the linker to put it into flash.


10 Jul 2011

Well, what is the code that is generating the error?

10 Jul 2011


The const operator only tell the linker to put it into flash.

This is incorrect. Yes, in our embedded enviroment one would assume the compiler/linker is smart enough to do what you are expecting.

However, consider the function prototype:-

int my_func(const char *s);

In that context const has a different meaning to what you are expecting.


10 Jul 2011

I want to put a bmp into flash. The bmp is defined as const char bmp[] = { ...... };

The graphic routine is defined as Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap)

If i use a bmp defined as char bmp[] = { ....} it is working, but the compiler use ram.

The same code is working with the Keil compiler....

Is there a macro to put the array into program space like the PROGMEM from the AVR compiler ?


10 Jul 2011

In my z80 emulator I use:

static const char rom[] = { 0x12, ........... };

To store the emulated ROM image in flash, works ok.

10 Jul 2011

const means, in the end, "don't change this". So if you declare your char array as const, it is un-modifiable. But if you define a function parameter as non-const, it means that the function is free to change it (even if it doesn't). Thats why the compiler complains about it - you give a non-modifiable variable to a modifiable parameter, which is not allowed. So either you need to change your function, or cast the parameter.