Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Const unsigned char ?

Status
Not open for further replies.

bianchi77

Advanced Member level 4
Joined
Jun 11, 2009
Messages
1,313
Helped
21
Reputation
44
Reaction score
20
Trophy points
1,318
Location
California
Activity points
9,442
Guys,

I tried to use unsigned char below, but I got error, how can I fix it ?

Code:
const unsigned char data[] = {0xFF,0xF2,0x40,0xC0,0x19,0xB7,0x00,0x14,0x02,0xE6,0x5C,};
unsigned char *q;
q = data ;


Code:
..\Src\main.c(274): error:  #513: a value of type "const unsigned char *" cannot be assigned to an entity of type "unsigned char *"
                q = data;

Thank you
 
Last edited:

Hi,

I may be wrong, but isn't char always unsigned, and it doesn't need the word "unsigned".

INT can be signed or unsigned.

Klaus
 

Replace

Code:
const unsigned char data[] = {0xFF,0xF2,0x40,0xC0,0x19,0xB7,0x00,0x14,0x02,0xE6,0x5C,};

with

Code:
unsigned char data[] = {0xFF,0xF2,0x40,0xC0,0x19,0xB7,0x00,0x14,0x02,0xE6,0x5C};

In your array there is a comma in the end and that is the problem. Also you cannot create a const type array and assign the address to non const type pointer.
 

Phisicaly, it could be possible because some microcontrollers using common address space for ram/flash/eeprom like stm8/32. So it is just a changing pointer to first address location. And it could work with type conversion like (const char *), but also will became unsave and can increase the risk on instability.
 

The problem can't be "fixed" without considering the memory model of your processor (which isn't mentioned at all) and how the specific compiler (must be known too) is implementing arrays of constant data.

I presume that the topic is somewhere discussed in the compiler user manual, did you review it at all? The compiler might provide a dedicated pointer type for constant data.
 

I think the compiler is having a problem with assigning a non-cont pointer to a const array. Given that declaration of the pointer, it implies that you can assign a new value to the pointed-to value which is not the case (as it might be stored in ROM as it is 'const').
Susan
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top