View previous topic :: View next topic |
Author |
Message |
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
array of pointers? |
Posted: Sat May 04, 2013 7:01 am |
|
|
Hi
Can anyone explain why function point1 is not working in CCS.
It is tested in real hw.
Compiler: 4140 - I have 4141 but it is not installed.
PIC:18F26K22
In "Code::Blocks" both ex work nice.
Code: |
void p1(char *p[]){//Not working Print only some of the array?
int i;
for (i=1; i<7; i++){
printf("*P[]:%u_%s\r\n",i,p[i]);
}
}
void p2(char **p){//working Print it all
int i;
for (i=1; i<7; i++){
printf("**P:%u_%s\r\n",i,p[i]);
}
}
void pmain(){
int i;
static char string[]={"1;2;3;4;5;6;7;8;9;0"};
char *Cmdptr[10];
char *p;
p=string;
Cmdptr[1]=strtok(p,";");
Cmdptr[2]=strtok(NULL,";");
Cmdptr[3]=strtok(NULL,";");
Cmdptr[4]=strtok(NULL,";");
Cmdptr[5]=strtok(NULL,";");
Cmdptr[6]=strtok(NULL,";");
for (i=1; i<7; i++){
printf("Cmdptr:%u_%s\r\n",i,Cmdptr[i]);
}
p1(Cmdptr);
p2(Cmdptr);
}
|
Last edited by hmmpic on Sun May 05, 2013 2:14 am; edited 5 times in total |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat May 04, 2013 4:26 pm |
|
|
Post your PIC and your compiler version. |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sun May 05, 2013 1:16 am |
|
|
Hi
Compiler: 4140
PIC:18F26K22
I have 4141 but it is not installed. |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Sun May 05, 2013 1:44 am |
|
|
You should post meaningful code. How are the pointers initialized and what is exactly "not working"?
A NULL pointer can't work. |
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sun May 05, 2013 2:15 am |
|
|
First post is now updated with ex. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun May 05, 2013 12:23 pm |
|
|
This has been a problem for a long time. To make it work with the
array syntax, you have to remove "char *" and declare the function
parameter as an array of int16 values. (Pointers are 16 bits for 18F PICs).
Example:
Code: |
void p1(int16 p[]) {
int i;
for (i=1; i<7; i++){
printf("*P[]:%u_%s\r\n",i,p[i]);
}
} |
This works in vs. 4.141, but I think in some earlier versions you might
also have to put in the array size. For example, in your case:
Code: |
void p1(int16 p[10]) {
|
|
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Mon May 06, 2013 4:17 am |
|
|
Hi @PCM p..
Thanks for information. |
|
|
|