Important changes to forums

We’re making some changes to the Mbed forums. From 10th December 2019 all new discussions will take place on our new forum site. You can continue to reply to existing threads for the next two weeks. After that we will archive this forum so you can return to useful posts in the future.

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.

Peter

10 Jul 2011

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

10 Jul 2011

Quote:

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.

See http://en.wikipedia.org/wiki/Const-correctness

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 ?

Peter

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.

You need to log in to post a reply