View previous topic :: View next topic |
Author |
Message |
Regas
Joined: 08 Jan 2010 Posts: 8
|
Problem with PCD compiler and const declaration |
Posted: Fri Jan 08, 2010 5:21 am |
|
|
The following code fragment works well:
Code: |
char Strg[] ={"Test"};
int8 ii;
ii =0;
while (Strg[ii] !=0){
++ii;
}
|
But when I use a const variable:
Code: |
const char Strg[] ={"Test"};
int8 ii;
ii =0;
while (Strg[ii] !=0){
++ii;
}
|
The program execution failed by entering the while loop.
The list File contains a call statement to an empty ROM location.
Code: |
004AA EF6862 CLR.B 862 : [862] = 0
.............................. while (Strg[ii] !=0){
004AC BFC862 MOV.B 862,W0L : W0L = [862]
004AE FB0000 SE W0,W0 : W0 = sign-extended W0
004B0 020100 000000 CALL 100 :
004B4 E00400 CP0.B W0L : Status set for W0L - 0
004B6 320003 BRA Z,4BE : if W0L=0 GoTo 4BE
.............................. ++ii;
004B8 EC6862 INC.B 0862 : [4BE] = [4BE] + 1
.............................. }
004BA 0404AC 000000 GOTO 4AC :
|
How can I use const variables with PCD compiler?
PS: The const declaration works well by using PCH compiler. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Jan 08, 2010 9:36 am |
|
|
Your const string example is working for me with PCD V4.104.
Quote: | The list File contains an call statement to an empty ROM location | Did you check the ROM content?
The code is not listed, unless you remove the #nolist pragma from the header file. |
|
|
Regas
Joined: 08 Jan 2010 Posts: 8
|
|
Posted: Fri Jan 08, 2010 3:42 pm |
|
|
Hi FvM
Thank you for help.
Yes I use PCD V4.104.
The last posted routine is really working when compiled separately sorry.
I could not find the
in the header file, but the constant tables are not listed in the list file.
In the following code the string "ADC Kanal2_A" gives no output. But when I remove the declaration const both strings will work.
Code: |
char ADC1[] ={ "ADC Kanal1_V"};
const char ADC2[] ={ "ADC Kanal2_A"};
.
.
.
switch (LCDSw){
case 1 : if (LCD_Ausgabe (41, &ADC1)) LCDSw =2;
break;
case 2 : if (LCD_Ausgabe (61, &ADC2)) LCDSw =3;
break;
.
.
.
|
Are pointers not allowed with const strings ? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Jan 08, 2010 4:03 pm |
|
|
Yes, pointers make the difference. The problem is, that a const string pointer can be only dereferenced by a
TBLRD instruction sequence, so it has to be treated different by the compiler. According to reported CCS C
features, constant string pointers should work now, but I never saw it with PCD. It surely didn't work e.g. half
a year ago, and I didn't try with newer versions. But you should check yourself. Surely, it must use a different
pointer type in LCD_Ausgabe().
To tell my personal opinion: The mixture of unclear documentation and announced but actually unsupported
features doesn't really motivate me to check for updated compiler functionality.
Best regards,
Frank |
|
|
|