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 support@ccsinfo.com

Error Not enough RAM for all variables

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



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

Error Not enough RAM for all variables
PostPosted: Wed Mar 03, 2021 10:10 am     Reply with quote

Hello,
I tried to use text table in CCS I already use with XC8 compiler. This because my string isn't length fixed. Below example of structure of table. In production firmware I have 5 tables with total each composed of 40 text string.

When I compile with CCS V5.077 I have compiler error:
Error Not enough RAM for all variables

Why happens so ? I don't use RAM for tables.

Thanks for help !

Code:

cont int *tab_msg_EN[5]{
"11111111\0",
"22222222\0",
"333\0",
"44444\0",
"5555\0",
};
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Wed Mar 03, 2021 11:37 am     Reply with quote

I solved getting back and use array of strings without pointer.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Mar 04, 2021 12:56 am     Reply with quote

Here is how to make variable length constant strings work. The program
below displays the following output in MPLAB vs. 8.92 simulator. This was
tested with CCS vs. 5.103. See the CCS manual on page 49.
Quote:

11111111
22222222
333
44444
5555

Test program:
Code:

#include <18F46K22.h>
#use delay(internal=4M)
#use rs232(baud=9600, UART1, ERRORS)

const int8 tab_msg_EN[][*] = {
"11111111\0",
"22222222\0",
"333\0",
"44444\0",
"5555\0"
};


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

for(i=0; i<5; i++)
   {
    printf("%s \r", tab_msg_EN[i]);
   }


while(TRUE);
}


Also, you don't have to put \0 at the end of your strings. The compiler
automatically puts a \0 at the end of a quoted string. So you can do it
like this and it will still work:
Code:

const int8 tab_msg_EN[][*] = {
"11111111",
"22222222",
"333",
"44444",
"5555"
};
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Thu Mar 04, 2021 1:53 am     Reply with quote

Your help is greatly appreciated. I'm going to work around and test it.

Regards,
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Thu Mar 04, 2021 2:04 am     Reply with quote

What was originally posted, would work without the problem, with one
simple change.

Just add:

#device PASS_STRINGS=IN_RAM

just up after the processor definitions.

The 'reason' for the problem is simple. On the PIC, the ROM memory
space is a separate address space to the RAM. So trying to declare an array
of pointers results in addresses that are way outside the RAM area.

The PASS_STRINGS option makes the compiler 'virtualise' pointers to the
ROM. This is the default behaviour in XC8.
So:
(Using PCM Programmers example)
Code:

#include <18F46K22.h>
#device PASS_STRINGS=IN_RAM
#use delay(internal=4M)
#use rs232(baud=9600, UART1, ERRORS)

const int8 * tab_msg_EN[] = {
"11111111",
"22222222",
"333",
"44444",
"5555"
};


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

for(i=0; i<5; i++)
   {
    printf("%s \r", tab_msg_EN[i]);
   }


while(TRUE);
}


Will merrily work.
Fabri



Joined: 22 Aug 2005
Posts: 275

View user's profile Send private message

PostPosted: Thu Mar 04, 2021 2:11 am     Reply with quote

Very interesting Ttelmah.

Thanks
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