CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Function params -> confusing

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

Function params -> confusing
PostPosted: Sat Oct 09, 2010 5:08 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 12:46 pm     Reply with quote

Read these threads:
http://www.ccsinfo.com/forum/viewtopic.php?t=42070&highlight=harvard
http://www.ccsinfo.com/forum/viewtopic.php?t=34837&highlight=harvard
hmmpic



Joined: 09 Mar 2010
Posts: 314
Location: Denmark

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 1:11 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Oct 09, 2010 1:18 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group