F
Frank
Hi,
I am developing an application on PPC405 (Walnut). The compiler I am
using is GCC. But somehow the string pointer in a C function doesn't
work. The code is as below:
void example() {
char *str = "this is a test";
while (*str != 0) {
putc(*str++);
}
return;
}
putc() is a function to put a char on the serial console.
This function ends up with a strange string on the serial console
"><...HH..>>..."
But if I modify the function to the following one:
void example_modified() {
char str[10] = \
{'t','h','i','s',' ','i','s',' ','a',' ','t','e','s','t','\0'};
int i = 0;
for (i = 0; str != 0; i++) {
putc(str);
}
return;
}
Then it works. So I am wondering if there is something wrong with the
stack setting. Can anybody tell me what makes the above two functions
different? Why the char array str[10] works while the string pointer
str* doesn't work?
Thanks!
Frank
I am developing an application on PPC405 (Walnut). The compiler I am
using is GCC. But somehow the string pointer in a C function doesn't
work. The code is as below:
void example() {
char *str = "this is a test";
while (*str != 0) {
putc(*str++);
}
return;
}
putc() is a function to put a char on the serial console.
This function ends up with a strange string on the serial console
"><...HH..>>..."
But if I modify the function to the following one:
void example_modified() {
char str[10] = \
{'t','h','i','s',' ','i','s',' ','a',' ','t','e','s','t','\0'};
int i = 0;
for (i = 0; str != 0; i++) {
putc(str);
}
return;
}
Then it works. So I am wondering if there is something wrong with the
stack setting. Can anybody tell me what makes the above two functions
different? Why the char array str[10] works while the string pointer
str* doesn't work?
Thanks!
Frank