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

Compiler error initialising strings?

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



Joined: 18 Mar 2019
Posts: 6

View user's profile Send private message

Compiler error initialising strings?
PostPosted: Mon Mar 18, 2019 11:26 am     Reply with quote

Hello,

I'm compiling this exact code in CCS PIC C version 5.025.

If I put 11 in SIZE, which would be the correct size since all strings are 10 positions plus \0 added by compiler, the variables simply don't get the correct value. This happens in Proteus and also in the product the code goes to.
For example:
STR_GIRO should be " GIRO \0" but instead is "GGGGGGGGGGG".
STR_EXTE should be " EXTENSAO \0" but instead is " EXTENSA\0\0\0".

If I put 10 in SIZE, variables are truncated but correct, just without ending \0.
If I put 12 in SIZE, variables are correct but with twice \0 at the end.
If I put 11 in SIZE, but exclude variables STR_EXTJB to STR_F_HIDR, the rest is as it should be.
Changing between styles int8 STR_GIRO [SIZE] = " GIRO " to int8 STR_GIRO [SIZE] = {" GIRO "} does not change the result.

Why would this be happening?

Code:

#include <18F67K22.h>
#device ADC = 12

#FUSES WDT       
#FUSES WDT256   
#FUSES VREGSLEEP
#FUSES SOSC_DIG 
#FUSES NOXINST   
#FUSES NOFCMEN   
#FUSES NOIESO   
#FUSES PUT       
#FUSES BROWNOUT 
#FUSES BORV27   
#FUSES BORM_MED 
#FUSES RTCOSC_INT
#FUSES MSSPMSK7 
#FUSES MCLR     
#FUSES STVREN   
#FUSES BBSIZ2K   
#FUSES PROTECT   
#FUSES NOCPB     
#FUSES NOCPD     
#FUSES NOWRT     
#FUSES NOWRTC   
#FUSES NOWRTB   
#FUSES NOWRTD   
#FUSES NOEBTR   
#FUSES NOEBTRB   

#use delay(crystal = 20000000)

#zero_ram

#define SIZE 11

int8 STR_GIRO  [SIZE] = "   GIRO   ";
int8 STR_ELEV  [SIZE] = " ELEVACAO ";
int8 STR_INCL  [SIZE] = "INCLINACAO";
int8 STR_EXTE  [SIZE] = " EXTENSAO ";
int8 STR_GUIN  [SIZE] = " GUINCHO  ";
int8 STR_EXTJB [SIZE] = " EXT JIBE ";
int8 STR_INCJB [SIZE] = " INC JIBE ";
int8 STR_AUX   [SIZE] = " AUXILIAR ";
int8 STR_MANIP [SIZE] = "MNP. POSTE";
int8 STR_CH5   [SIZE] = " CANAL 5  ";
int8 STR_CH6   [SIZE] = " CANAL 6  ";
int8 STR_CH7   [SIZE] = " CANAL 7  ";
int8 STR_CH8   [SIZE] = " CANAL 8  ";
int8 STR_CESTO0[SIZE] = "GIRO INF. ";
int8 STR_CESTO1[SIZE] = "ELEV. INF.";
int8 STR_CESTO2[SIZE] = "GIRO SUP. ";
int8 STR_CESTO3[SIZE] = "ELEV. SUP.";
int8 STR_CESTO4[SIZE] = "BASCULAM. ";
int8 STR_F_HIDR[SIZE] = "FER. HIDR.";

int8 joys[][SIZE] = {"   GIRO   ", " ELEVACAO ", "INCLINACAO", " EXTENSAO ", " GUINCHO  ", " EXT JIBE ", " INC JIBE ", " AUXILIAR "}; // Initial names

void main() {
   while (TRUE) {
      restart_wdt();
     
      // Names will be sprinted to joys during execution
   }
}


Last edited by Jhonatan on Mon Mar 18, 2019 12:30 pm; edited 1 time in total
dluu13



Joined: 28 Sep 2018
Posts: 395
Location: Toronto, ON

View user's profile Send private message Visit poster's website

PostPosted: Mon Mar 18, 2019 12:08 pm     Reply with quote

How are you printing them out or otherwise inspecting their contents?

I didn't put it on my PIC, but it works alright on the compiler on my computer.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 12:14 pm     Reply with quote

this...
restart_wdt();

is really not required and should NOT be coded until the product is ready to be shipped !
Jhonatan



Joined: 18 Mar 2019
Posts: 6

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 12:29 pm     Reply with quote

In deed there are no errors at all (please disconsider the variables are not used in the code posted).

I'm debugging the values of the variables in Proteus CPU variables right after
the source enters main.

On the product there are lines like:
sprintf(joys[0], STR_GIRO);
Then later:
fprintf(lcd_write, "%s ", joys[0]);

Also, it works fine if all other variables but joys are const.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 12:34 pm     Reply with quote

The program below works with CCS vs. 5.082. It displays the following
output in the Output Window in MPLAB vs. 8.92 simulator:
Quote:
GIRO
ELEVACAO
INCLINACAO
EXTENSAO
GUINCHO
EXT JIBE
INC JIBE
AUXILIAR

Test program:
Code:
#include <18F67K22.h>
#device ADC = 12
#fuses NOWDT, BORV27, PUT, SOSC_DIG, NOPROTECT
#use delay(crystal = 20000000)
#use rs232(baud=9600, UART1, ERRORS)

#define SIZE 11

int8 joys[][SIZE] =
{
{"   GIRO   "},
{" ELEVACAO "},
{"INCLINACAO"},
{" EXTENSAO "},
{" GUINCHO  "},
{" EXT JIBE "},
{" INC JIBE "},
{" AUXILIAR "}
};

//===========================================
void main()
{
int8 i;

for(i = 0; i < 8; i++)
  printf("%s\r", joys[i]);

while(TRUE);
}

Jhonatan



Joined: 18 Mar 2019
Posts: 6

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 12:50 pm     Reply with quote

Hi PCM programmer.
Would you remake the test with this code?

This does not print even "TEST":
Code:

#include <18F67K22.h>
#device ADC = 12
#fuses NOWDT, BORV27, PUT, SOSC_DIG, NOPROTECT
#use delay(crystal = 20000000)
#use rs232(baud=9600, UART1, ERRORS)

#define SIZE 11

int8 STR_GIRO  [SIZE] = "   GIRO   ";
int8 STR_ELEV  [SIZE] = " ELEVACAO ";
int8 STR_INCL  [SIZE] = "INCLINACAO";
int8 STR_EXTE  [SIZE] = " EXTENSAO ";
int8 STR_GUIN  [SIZE] = " GUINCHO  ";
int8 STR_EXTJB [SIZE] = " EXT JIBE ";
int8 STR_INCJB [SIZE] = " INC JIBE ";
int8 STR_AUX   [SIZE] = " AUXILIAR ";
int8 STR_MANIP [SIZE] = "MNP. POSTE";
int8 STR_CH5   [SIZE] = " CANAL 5  ";
int8 STR_CH6   [SIZE] = " CANAL 6  ";
int8 STR_CH7   [SIZE] = " CANAL 7  ";
int8 STR_CH8   [SIZE] = " CANAL 8  ";
int8 STR_CESTO0[SIZE] = "GIRO INF. ";
int8 STR_CESTO1[SIZE] = "ELEV. INF.";
int8 STR_CESTO2[SIZE] = "GIRO SUP. ";
int8 STR_CESTO3[SIZE] = "ELEV. SUP.";
int8 STR_CESTO4[SIZE] = "BASCULAM. ";
int8 STR_F_HIDR[SIZE] = "FER. HIDR.";

int8 joys[][SIZE] =
{
{"   GIRO   "},
{" ELEVACAO "},
{"INCLINACAO"},
{" EXTENSAO "},
{" GUINCHO  "},
{" EXT JIBE "},
{" INC JIBE "},
{" AUXILIAR "}
};

//===========================================
void main()
{
int8 i;
   printf("TEST");
   
   sprintf(joys[0], STR_CH5);
   printf("%s\r", joys[0]);

while(TRUE);
}


This prints "TEST":
Code:
#include <18F67K22.h>
#device ADC = 12
#fuses NOWDT, BORV27, PUT, SOSC_DIG, NOPROTECT
#use delay(crystal = 20000000)
#use rs232(baud=9600, UART1, ERRORS)

#define SIZE 11

/*int8 STR_GIRO  [SIZE] = "   GIRO   ";
int8 STR_ELEV  [SIZE] = " ELEVACAO ";
int8 STR_INCL  [SIZE] = "INCLINACAO";
int8 STR_EXTE  [SIZE] = " EXTENSAO ";
int8 STR_GUIN  [SIZE] = " GUINCHO  ";
int8 STR_EXTJB [SIZE] = " EXT JIBE ";
int8 STR_INCJB [SIZE] = " INC JIBE ";
int8 STR_AUX   [SIZE] = " AUXILIAR ";
int8 STR_MANIP [SIZE] = "MNP. POSTE";
int8 STR_CH5   [SIZE] = " CANAL 5  ";
int8 STR_CH6   [SIZE] = " CANAL 6  ";
int8 STR_CH7   [SIZE] = " CANAL 7  ";
int8 STR_CH8   [SIZE] = " CANAL 8  ";
int8 STR_CESTO0[SIZE] = "GIRO INF. ";
int8 STR_CESTO1[SIZE] = "ELEV. INF.";
int8 STR_CESTO2[SIZE] = "GIRO SUP. ";
int8 STR_CESTO3[SIZE] = "ELEV. SUP.";
int8 STR_CESTO4[SIZE] = "BASCULAM. ";
int8 STR_F_HIDR[SIZE] = "FER. HIDR.";*/

int8 joys[][SIZE] =
{
{"   GIRO   "},
{" ELEVACAO "},
{"INCLINACAO"},
{" EXTENSAO "},
{" GUINCHO  "},
{" EXT JIBE "},
{" INC JIBE "},
{" AUXILIAR "}
};

//===========================================
void main()
{
int8 i;
   printf("TEST");
   
   //sprintf(joys[0], STR_CH5);
   //printf("%s\r", joys[0]);

while(TRUE);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 12:55 pm     Reply with quote

There are a couple of comments:

5.025, was early enough that it may still have the gobal interrupts
being disabled by printf. Problem appeared in the early V5 compilers,
and was fixed some time later. Might still be applying in this version.

He has the watchdog enabled. This might well be interfering with
an output like printf.

Also as has already been commented about the watchdog, don't
enable 'PROTECT' until development is finished. Having this enabled
results in extra lives being used on the program memory when
developing.

He also has a boot block size enabled. Why?.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 1:06 pm     Reply with quote

There's definitely a problem with vs. 5.025. In his post with the two
programs, I compiled the first one with vs. 5.082 and ran it in MPLAB 8.92
simulator and I got:
Quote:
TEST CANAL 5

That's correct.

Then I uninstalled vs. 5.082 and installed vs. 5.025. I re-compiled and
got this:
Quote:
TEST

Also, Ttelmah, I got rid of all that in my test program.
Jhonatan



Joined: 18 Mar 2019
Posts: 6

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 1:33 pm     Reply with quote

Sorry Ttelmah and temtronic, this is actually 9th version of a program already running on an old product and I'm just adding some extra functions, which are the extra strings I put here. My first post had unnecessary coding to show the problem.

Thank you PCM programmer for the better code and for testing this out for me, that confirms my thoughts.

This code (which is the same as previous but commented) shows the point. When I added extra string names for the joys, it stopped working. Literally commenting and uncommenting these lines screws the behaviour:

Code:
#include <18F67K22.h>
#device ADC = 12
#fuses NOWDT, BORV27, PUT, SOSC_DIG, NOPROTECT
#use delay(crystal = 20000000)
#use rs232(baud=9600, UART1, ERRORS)

#define SIZE 11

// These names will be sprinted to joys during execution
int8 STR_GIRO  [SIZE] = "   GIRO   ";
int8 STR_ELEV  [SIZE] = " ELEVACAO ";
int8 STR_INCL  [SIZE] = "INCLINACAO";
int8 STR_EXTE  [SIZE] = " EXTENSAO ";
int8 STR_GUIN  [SIZE] = " GUINCHO  ";

// if I comment from here
int8 STR_EXTJB [SIZE] = " EXT JIBE ";
int8 STR_INCJB [SIZE] = " INC JIBE ";
int8 STR_AUX   [SIZE] = " AUXILIAR ";
int8 STR_MANIP [SIZE] = "MNP. POSTE";
int8 STR_CH5   [SIZE] = " CANAL 5  ";
int8 STR_CH6   [SIZE] = " CANAL 6  ";
int8 STR_CH7   [SIZE] = " CANAL 7  ";
int8 STR_CH8   [SIZE] = " CANAL 8  ";
int8 STR_CESTO0[SIZE] = "GIRO INF. ";
int8 STR_CESTO1[SIZE] = "ELEV. INF.";
int8 STR_CESTO2[SIZE] = "GIRO SUP. ";
int8 STR_CESTO3[SIZE] = "ELEV. SUP.";
int8 STR_CESTO4[SIZE] = "BASCULAM. ";
int8 STR_F_HIDR[SIZE] = "FER. HIDR.";
// to here, it works fine

int8 joys[][SIZE] = { // This is just to initialize
   {"   GIRO   "},
   {" ELEVACAO "},
   {"INCLINACAO"},
   {" EXTENSAO "},
   {" GUINCHO  "},
   {" EXT JIBE "},
   {" INC JIBE "},
   {" AUXILIAR "}
};

void main() {
   printf("TEST");
   
   sprintf(joys[0], STR_GIRO);
   printf("%s\r", joys[0]);
   
   while(TRUE);
}


I think the compiler is doing something wrong as there is more RAM to be initialized.
Also, on Proteus (sorry for insisting in Proteus), there are warnings concerning PC 0x0242 to PC 0x0246 where attempts to change RTCVALL and RTCVALH were denied and also "external memory not modeled, write to MEMCON just store data in the register".
All that disappears if I comment that block.

I will try to get the last version of the compiler. Would you recommend any particular or vs. 5.082?

Thank you all.
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Mon Mar 18, 2019 2:28 pm     Reply with quote

Yes. A quick test shows it works on 5.028, but not on the versions before.
The functions being complained about by Proteus are not at the heart of the
problem, they are just things that Proteus doesn't know how to model.
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