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

Pointers into ROM

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



Joined: 14 Apr 2015
Posts: 28
Location: Boulder Creek, CA

View user's profile Send private message

Pointers into ROM
PostPosted: Fri May 15, 2015 2:59 pm     Reply with quote

Experimentation shows this to be true, but I want to verify it with those in-the-know.

The following code segment has the correct behavior:

Code:
   char *letters[] = {"ab", "cd", "ef", "gh", "ij") ;

   for(int i = 0; i < 5; i++)
   {
      func1(letters[i]) ;
   }

However, if you put a const in front of the char *, the strings are not dealt with correctly. Pointers into the ROM area do not work. And no compiler errors for 5.0.18.

Have I got that right?
_________________
D. Scruggs
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Fri May 15, 2015 3:05 pm     Reply with quote

march 2015 manual for 5.042+ says:
Quote:

(type qualifier) ROM Forces data into program memory. Pointers may be used to this data but they can not be mixed with RAM pointers.


and while i recognize THIS declaration:
Code:
const char *cptr;


i am unfamiliar with how you expect YOUR declaration of a character array ending with a ')' to work at all.
certainly that line does not compile for you as listed does it ?
it does not for me........
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 15, 2015 3:27 pm     Reply with quote

Here is one way to do it. This program displays the following output in
MPLAB simulator (MPLAB vs. 8.92):
Code:
ab cd ef gh ij

Test program:
Code:
#include <18F4620.h>
#device PASS_STRINGS=IN_RAM
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

void func1(char *ptr)
{
printf(ptr);
putc(' ');
}

//========================
void main()
{
char const letters[5][3] = {"ab", "cd", "ef", "gh", "ij"} ;

for(int i = 0; i < 5; i++)
   {
    func1(letters[i]) ;
   }

while(1);
}

There might also be a way to do it using 'rom' pointers.
bcfd36



Joined: 14 Apr 2015
Posts: 28
Location: Boulder Creek, CA

View user's profile Send private message

PostPosted: Fri May 15, 2015 3:36 pm     Reply with quote

Obviously, the ")" was a typo and should have been a "}". I typed in the segment, not cut and paste.

And I am using 5.018 (not my choice).

So you found a coding error, but didn't answer the question.

The FAQ in the CCS manual, under "How can a constant data table be
placed in ROM?" states you cannot have something like

Code:

byte const table[5] = {1,2,3,4,5};
ptr = &table[i]


if table is in ROM. I believe the const char * would fall into the same category.

Do you know a way around this?
_________________
D. Scruggs
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri May 15, 2015 3:41 pm     Reply with quote

Did you see my post ?
bcfd36



Joined: 14 Apr 2015
Posts: 28
Location: Boulder Creek, CA

View user's profile Send private message

PostPosted: Fri May 15, 2015 4:15 pm     Reply with quote

PCM Programmer,
Yep, saw your post later in the discussion.

Unfortunately, in my real world program, the strings in the char * array are not all the same length. Making them all the same length would chew up a bunch of space that was not really being used.

Also, "rom pointers"? I haven't found a reference to that. Yet. I'll go look.

I appreciate the reply though
_________________
D. Scruggs
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