|
|
View previous topic :: View next topic |
Author |
Message |
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
[Solved] CCS returning a constant string. |
Posted: Thu Feb 20, 2020 11:59 am |
|
|
In a PIC24 project I worked on a few months ago, I had debugging functions that would print out a text version of a value, such as:
Code: |
printf ("Command: %d (%s)\r\n", command, GetCommandString(command));
|
It worked well.
Another developer here is using a routine to return a string for a mode to display on an LCD, and sometimes it ends up pointing to 0s instead of the hard-coded string constant. I wrote a quick test program, and found mine also seems to point to NULL. I tested using 5.082 and 5.092.
I created a very simple test program, identical in flow to the routines I used earlier that worked. But today, it doesn't work for me (and the other project works, unless he add some lines of code, then it starts returning a pointer to 0s).
Code: | #include <main.h>
// Prototypes
const char *GetName(int nameValue);
// Functions
void main()
{
printf (__DATE__" "__TIME__"\r\n");
for (int idx = 0; idx < 5; idx++)
{
printf ("%d = '%s'\r\n", idx, GetName(idx));
}
while(TRUE);
}
const char *GetName(int nameValue)
{
printf ("GetName(%d)\r\n", nameValue);
switch (nameValue)
{
case 0:
return "Zero";
case 1:
return "One";
case 2:
return "Two";
default:
return "???";
}
}
// End of main.c |
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ?
Last edited by allenhuffman on Thu Feb 20, 2020 2:18 pm; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Thu Feb 20, 2020 12:09 pm |
|
|
You need to either be enabling PSV, or using PASS_STRINGS=IN_RAM to
support this. Much more efficient to enable PSV, |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Feb 20, 2020 12:16 pm |
|
|
Ttelmah wrote: | You need to either be enabling PSV, or using PASS_STRINGS=IN_RAM to
support this. Much more efficient to enable PSV, |
Ah, that could have been enabled in the project I was doing this in, though we don't use any strings (no I/O).
I just added that in my master header file, but no change. The ptr being returns is correct, however, and matches where the data in flash is located. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Feb 20, 2020 12:34 pm |
|
|
Changing from constant quotes to const strings works. Oddly.
Code: | #include <main.h>
// Prototypes
const char *GetName(int nameValue);
// Functions
void main()
{
printf (__DATE__" "__TIME__"\r\n");
for (int idx = 0; idx < 5; idx++)
{
printf ("%d = 0x%x '%s'\r\n", idx, GetName(idx), GetName(idx));
}
while(TRUE);
}
const char *zero = "Zero";
const char *one = "One";
const char *two = "Two";
const char *unknown = "???";
const char *GetName(int nameValue)
{
//printf ("GetName(%d)\r\n", nameValue);
switch (nameValue)
{
case 0:
//return "Zero";
return zero;
case 1:
//return "One";
return one;
case 2:
//return "Two";
return two;
default:
//return "???";
return unknown;
}
}
// End of main.c
|
Quote: | 20-Feb-20 12:33:14
0 = 0x802 'Zero'
1 = 0x808 'One'
2 = 0x80c 'Two'
3 = 0x810 '???'
4 = 0x810 '???'
|
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Feb 20, 2020 2:15 pm |
|
|
CCS replied.
That makes the 'return "string"' work. Cool. That must have been in the pre-exiting project that I was working with.
Quote: | CONST=READ_ONLY
Uses the ANSI keyword CONST definition, making CONST variables read only, rather than located in program memory.
CONST=ROM
Uses the CCS compiler traditional keyword CONST definition, making CONST variables located in program memory.
|
_________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9243 Location: Greensville,Ontario
|
|
Posted: Thu Feb 20, 2020 4:05 pm |
|
|
keep going back in versions until it works again.....
I copy/change/compile/test....
If I don't like it, I go back....
pgmv1,pgmv2,......pgmv999
I know it's a lot of HD space, but there's lots available.
Once the project is done,I then delete all but last 3-5 versions. Well I should but really HD space is unlimited, right ? |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Thu Feb 20, 2020 4:19 pm |
|
|
temtronic wrote: | keep going back in versions until it works again..... |
Yeah, the history in the CCS editor is a nice bonus. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19539
|
|
Posted: Fri Feb 21, 2020 2:24 am |
|
|
Is the current failure with 5.092?.
This seems to have an 'oddity' if you do a lot of changes, that it then
stops working. Creates different output from what it gives after a clean
'launch'. I've noted it and reported this to CCS.
Could explain why you are seeing it working 'sometimes'....
Might be tempted to suggest you try re-installing the compiler. I have
(very occasionally) seen odd issues that seem to come down to a corrupted
installation. Have just tried you code with every combination I could think
of (PSV, PASS_STRINGS, const= etc.), and all worked correctly.... |
|
|
allenhuffman
Joined: 17 Jun 2019 Posts: 554 Location: Des Moines, Iowa, USA
|
|
Posted: Fri Feb 21, 2020 10:06 am |
|
|
Ttelmah wrote: | Is the current failure with 5.092?.
This seems to have an 'oddity' if you do a lot of changes, that it then
stops working. Creates different output from what it gives after a clean
'launch'. I've noted it and reported this to CCS.
Could explain why you are seeing it working 'sometimes'.... |
I am so glad we aren't the only ones! :-) I am in the habit of closing all windows and shutting down CCS, then double-clicking the next project file to make that one open. It seems to write files from the old project into the new one if I select it other ways. I may do a quick remove/clean install today, though I'm on my temporary Windows 7 machine again while the DELL laptop is back in the shop. _________________ Allen C. Huffman, Sub-Etha Software (est. 1990) http://www.subethasoftware.com
Embedded C, Arduino, MSP430, ESP8266/32, BASIC Stamp and PIC24 programmer.
http://www.whywouldyouwanttodothat.com ? |
|
|
|
|
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
|