954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

declaring constant array

Hi,

I want to declare an array of constant values in my header file, and this array cannot be changed in the main code.

const uchar x[4] = {1, 2, 3, 4} does not work, cos the linker will complain that the address space overflow.

Is there any way to do this?

Thanks in advance!

YYE

yye
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

const unsigned char x[4] = {1, 2, 3, 4};
http://ideone.com/EHqa1

This works fine. I note that you're putting int values into char types; is that deliberate?

Moschops
Practically a Master Poster
620 posts since Sep 2008
Reputation Points: 258
Solved Threads: 117
 

It was just an example.

I am trying to program into a Philips microcontroller, but it keeps returning an error when building, saying that the address space overflow.

This works in mircochip but not in the philips microcontroller.

I need an array that I can call and I do not want the program to change the values in the array.

So far I have googled and found nothing. Do you have any other ideas?

const unsigned char x[4] = {1, 2, 3, 4}; http://ideone.com/EHqa1

This works fine. I note that you're putting int values into char types; is that deliberate?

yye
Newbie Poster
2 posts since Nov 2011
Reputation Points: 10
Solved Threads: 0
 

Sounds like the issue isn't your code, but the limitations of your hardware. Without knowing what your hardware limitations are, it's tricky to advise, but many such devices allow you to specify sections of memory to use. Dig out the manual and see what's available to you.

Moschops
Practically a Master Poster
620 posts since Sep 2008
Reputation Points: 258
Solved Threads: 117
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: