??? 03/13/06 20:33 Read: times |
#112097 - Keil C51 and pointers as parameters |
Hi, guys. Something that should be simple is not working and driving me bonkers. I'm using a SiLabs '006 and Keil C51 7.04. None of this stuff is handled in an ISR.
Given a function: char Processor(char *foo, char strlen) { bit done = 0; char cnt = 0; char bar; while (!done) { bar = GetNextChar(); ++cnt; if ((bar == '\n') || (bar == strlen)) done = 1; else { *foo = bar; ++foo; } // if bar } // while return cnt; } // Processor called by: void doProcess(void) { char bletch[16]; // holds processed results char numchars; ... numchars = Processor(bletch, sizeof(bletch)); ...(Basically, I'm fetching characters from a FIFO, and looking for a carriage return and also making sure I don't overflow my buffer.) I'm having the following weird problem: the assignment *foo = bar;isn't happening. I've tried calling the function as numchars = Processor(&bletch[0], sizeof(bletch));which makes no difference. I've also tried putting bletch in the xdata space; also no difference. The compiler generates code that ultimately calls a library function (LCALL ?C?CSTPTR) that apparently does the copy, but when that call returns it's as if the copy never happened. I can post what the compiler generates, but I guess my question is: is it legal, at least with Keil's C51, to pass the address of a string to a function and use it in the function as I do? Seems to me this should work, and I have some working code elsewhere in my app that does almost the same thing. Instead of sending the address of an empty string to the function and having the function fill the string, the working code sends the address of the string to the function and that string is used one character at a time. Any ideas are appreciated. -a |
Topic | Author | Date |
Keil C51 and pointers as parameters | 01/01/70 00:00 | |
Wrong spelling | 01/01/70 00:00 | |
Foobar | 01/01/70 00:00 | |
FUBAR | 01/01/70 00:00 | |
Seems legal | 01/01/70 00:00 | |
re: seems legal![]() | 01/01/70 00:00 | |
here? | 01/01/70 00:00 |