janni wrote:Dany wrote:As soon as one tries to use the constant array in some way (here by using its address) the problem occurs.
Simple assignments will work (like bb := DescrConst[1]
as they're done without placing the constant in ROM.
Hi Janni, thanks for your reply.
This indeed gives no problem:
Code: Select all
I := DescrConst[3];
J := DescrConst[5];
but
this gives the linker problem:
Code: Select all
for I := 0 to SizeOf(DescrConst) - 1 do
begin
J := DescrConst[I];
// do something with J
end;
and also this code generates the error:
Code: Select all
for I := 0 to 9 do
begin
J := DescrConst[I];
// do something with J
end;
So, simply trying to step through the array is already too much asked for...
janni wrote:The bug is indeed limited to PIC16 processors, but there is hardly a simple workaround if the compiler cannot save constants.
Simple assignment is indeed sometimes Ok, but see my examples above: sometimes it is not Ok.
janni wrote:The only simple solution I see is to declare a variable and initialise it with the same data as the constant was supposed to contain.
That is indeed a work around, but this is a tradeoff between rom and ram usage. For some larger non changing data structures I want of course to use arrays in constant memory...
janni wrote:BTW, there is a way to force the compiler to save your array in ROM, but it may be not worth using.
Ha. What way?
janni wrote:You could describe what you want to achieve first.
Well, an example: I tried to make a "7 segments" library. This library would hold an array of the binary value of each segment (a..dp) and then also an array with the codes of which segments to use for each hex number to display:
Code: Select all
const // __7SegmentBits:
__a = $1; // bit 0
__b = $2; // bit 1
__c = $4; // bit 2
__d = $8; // bit 3
__e = $16; // bit 4
__f = $32; // bit 5
__g = $64; // bit 6
__dp = $128; // bit 7
__7SegmentCharacters: array[0..$0F] of byte = // each character is the sum of a number of segments
(
__a + __b + __c + __d + __e + __f, // character "0"
__b + __c, // character "1"
__a + __b + __g + __e + __d, // character "2"
__a + __b + __g + __c + __d, // character "3"
__f + __g + __b + __c, // character "4"
__a + __f + __g + __c + __d, // character "5"
__a + __f + __e + __d + __c + __g, // character "6"
__a + __b + __c, // character "7"
__a + __b + __c + __d + __e + __f, // character "8"
__a + __b + __g + __f + __c + __d, // character "9"
__a + __f + __e + __g + __b + __c, // character "A"
__f + __g + __c + __d + __e, // character "B"
__a + __f + __e + __d, // character "C"
__b + __g + __e + __d + __c, // character "D"
__a + __f + __g + __e + __d, // character "E"
__a + __f + __g + __e // character "F"
);
As soon as I try to address "__7SegmentCharacters" the linker error occurs...
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)