View previous topic :: View next topic |
Author |
Message |
hello188
Joined: 02 Jun 2010 Posts: 74
|
passing constant array pointer to function |
Posted: Fri Jun 10, 2011 11:40 am |
|
|
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
|
|
Posted: Fri Jun 10, 2011 12:23 pm |
|
|
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
|
|
Posted: Fri Jun 10, 2011 12:56 pm |
|
|
Also post your PIC. |
|
|
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Fri Jun 10, 2011 1:52 pm |
|
|
my compiler version is
4.120
and PIC is
18F46K22
Thanks guys |
|
|
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Fri Jun 10, 2011 2:11 pm |
|
|
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
|
|
Posted: Fri Jun 10, 2011 2:13 pm |
|
|
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
|
|
|
hello188
Joined: 02 Jun 2010 Posts: 74
|
|
Posted: Sun Jun 12, 2011 12:48 am |
|
|
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: 19504
|
|
Posted: Mon Jun 13, 2011 9:23 am |
|
|
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 |
|
|
|