I have some Const array tables that i want place in the flash/code memory of ARM controller. we can place array in code memory of C51 using "code" keyword. but how to place const array in ARM?
const unsigned char boot_version_string[16] __attribute__( (at(BOOTLOADER_TOKEN_ADDR) ) ) ="FEMBOOT 1.8";
Thankyou Tamir,
__attribute__( (at(BOOTLOADER_TOKEN_ADDR) ) ) keyword will work for 1 or 2 const arrays. but I want to place approximately 50 const arrays of different sizes, do i have to give address to all the arrays individually? Is there any way in which the compiler picks the address automatically?
Note that it's not the Compiler that picks addresses; it's the Linker - therefore, you need to be looking in the Linker Manual...
You need to read the linker manual. A short outline: you probably want to use a separate section, and to place that section using a scatter file. not elementary stuff I agree - but well documented.
do i have to give address to all the arrays individually? Is there any way in which the compiler picks the address automatically?
I have no idea why Tamir gave you this example. You didn't say that you wanted to place your data at a particular address, so it's safe to assume that you don't need the at attribute. All you need to do is declare your variables as const. This will put them in ROM. Compiler/linker will take care of assigning addresses, as usual.
Whew. I read the response and was wondering whether I was missing some important knowledge.
Putting const puts the tables into a code segment. If the code is in flash, then so are the tables.
I wrote a small program to Test the keywords, here the results are
with
const unsigned char a[3] __attribute__( (at(0x0010) ) )={'1','2','3'};
Result is: Program Size: Code=5126 RO-data=66 RW-data=16 ZI-data=560
const unsigned char a[3]={'1','2','3'};
Result is: Program Size: Code=5130 RO-data=66 RW-data=16 ZI-data=560
unsigned char a[3]={'1','2','3'};
Result: Program Size: Code=5130 RO-data=62 RW-data=20 ZI-data=556
if both attribute keyword and const keyword do the same thing, then why there is the variation in Code size?
Because they do not "do the same thing"!
They achieve the same end, but by doing different things!
Look again at those numbers, carefully: it's not just the code size that changes, is it...?