View previous topic :: View next topic |
Author |
Message |
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
Function params -> confusing |
Posted: Sat Oct 09, 2010 5:08 am |
|
|
Hi
I think it is confusing how CCS handle "const" params in functions.
Can someone explain this?
Code: | #include "18f4550.h"
//All FUSES missing _Only for compiler test not for using in PIC!
#Device PASS_STRINGS=IN_RAM
#use delay(clk=8M,internal)
#use RS232 (Baud=9600,UART1,Errors)
const char *LongString="12345678901234567890";
void FuncParam(char *par1){
printf("%s",par1);
}
void main(){
/*Is it normally that the pointer params is using space in RAM
If a long string is entered then the PIC ran out of memory in theory!
Why not store in ROM and just pass the pointer to the function?
*/
FuncParam("12345678901234567890"); //allocate all the string in ram too
FuncParam(LongString); // the same here
} |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
hmmpic
Joined: 09 Mar 2010 Posts: 314 Location: Denmark
|
|
Posted: Sat Oct 09, 2010 1:11 pm |
|
|
Hi
Thanks for reply and the link.
I still don't understand why CCS allocate RAM to all the size of the string?
In some other compiler they have no problem with handling the normally "C" way to use the "const" key word including in the function, and only address RAM to the pointer.
Whatever it wast of good RAM to allocate all const string in RAM too, buffer or not!
Are you sure this is not an compiler bug in some of the new 4.1xx release.
If i still have some old one 4.064 or something I will try compiling with that and see what happened. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Oct 09, 2010 1:18 pm |
|
|
Read this thread which partly discusses the issue of how other compilers
provide transparent support for pointers to ROM in the PIC. See
Mark's comments on the Hi-Tech compiler.
http://www.ccsinfo.com/forum/viewtopic.php?t=21588
In the past, I looked at the way Hi-Tech PIC16 compiler does it, and they
set a flag in the top bit of the 16-bit pointer to determine if it points to
ROM or RAM.
Question: How would you do this if you have a newer PIC which has more
than 32K of ROM ? The Hi-Tech method was invented in the older days
when a 16F877 was a big chip. There are some possible methods to do it,
but how much overhead is needed ? Is it worth it ? The bottom line is,
CCS is going to do it their way, regardless. |
|
|
|