CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem with PCD compiler and const declaration

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Regas



Joined: 08 Jan 2010
Posts: 8

View user's profile Send private message

Problem with PCD compiler and const declaration
PostPosted: Fri Jan 08, 2010 5:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 08, 2010 9:36 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jan 08, 2010 3:42 pm     Reply with quote

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
Code:
 #nolist pragma 

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

View user's profile Send private message

PostPosted: Fri Jan 08, 2010 4:03 pm     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group