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

passing constant array pointer to function

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



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

passing constant array pointer to function
PostPosted: Fri Jun 10, 2011 11:40 am     Reply with quote

Hi, I want to make a function that takes a variable length constant arrays.

I tried doing following
Code:

const int8 a[10];
const int8 b[3];

void function(int8 c[]){
//do something here

}

and call the function by
function(a);

However, the compiler gives me the error
Error 90 "main.c" Line 27(15,20): Attempt to create a pointer to a constant

I want to put the array in ROM as the data is too big to store in RAM.

Thank you
vinniewryan



Joined: 29 Jul 2009
Posts: 154
Location: at work

View user's profile Send private message MSN Messenger

PostPosted: Fri Jun 10, 2011 12:23 pm     Reply with quote

Check page 48 (pdf pg.60) in the CCS manual. It is possible to create a pointer to a constant. What is your compiler version?
_________________
Vinnie Ryan
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 12:56 pm     Reply with quote

Also post your PIC.
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 1:52 pm     Reply with quote

my compiler version is

4.120
and PIC is
18F46K22
Thanks guys
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 2:11 pm     Reply with quote

I found below example on CCS website

const char version[] = "PRODUCT ID V1.01";
const char *ptr;

However, it won't compile for some reason

Please help!!

Thank you
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 2:13 pm     Reply with quote

gives

Error 46 "F:\Jae\Software\Developing\IOJN\RCU890\def_var.h" Line 18(16,17): Expecting an =
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 2:21 pm     Reply with quote

I posted an example of how to use 'rom' pointers in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=45132
It works with your PIC with vs. 4.120.
hello188



Joined: 02 Jun 2010
Posts: 74

View user's profile Send private message

PostPosted: Sun Jun 12, 2011 12:48 am     Reply with quote

Thanks that post helped me a lot
However, as I code, problem still remains
I am still confused on the behavior of the ROM pointer

I wrote following code, and tested the register contents with debugger
Code:

#include<18F46K22.h>
#FUSES HSH, NOPLLEN, NOIESO, PUT, NOBROWNOUT, NOWDT, NOPBADEN, MCLR, STVREN, NODEBUG

rom int8 HELLO[5] = {'H','E','L','L','O'};
int8 debug_array[5]= {0,0,0,0,0};
int8 debug1 = 0;
int8 debug2 = 0;
int8 debug3 = 0;
int8 debug4 = 0;
void fun(rom *c){
   int8 k;
   for(k=0;k<5;k++) debug_array[k] = c[k];

   debug1 = debug_array[0];
   debug2 = c[0];
   debug3 = debug_array[1];
   debug4 = c[1];
   k = 1;
   debug5 = c[k];

}

void main(void){
   fun(HELLO);
   while(1);
}


and i get following results
debug_array = HELLO; //copied exactly same.
debug1 = 'H';
debug2 = 'H';
debug3 = 'E';
debug4 = 0;
debug5 = 'E';

debug4 should have been 'E' too. since debug_array[1] = c[k] where k = 1; and debug4= c[1];
I don't understand

what is the difference betweeen addressing array using variable and constant?
Thanks for helping guys
Ttelmah



Joined: 11 Mar 2010
Posts: 19535

View user's profile Send private message

PostPosted: Mon Jun 13, 2011 9:23 am     Reply with quote

What you post doesn't work, since you only declare debug1 to 4, yet use debug5. Suggest you keep the actual posting and test code the same. Probably a similar fault is causing the problem....

Best Wishes
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