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 support@ccsinfo.com

char * function parameter sendmessage(char *);

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







char * function parameter sendmessage(char *);
PostPosted: Fri Jan 31, 2003 7:02 am     Reply with quote

I try to make a function who receive a char pointer, and it's doesn't work, this is my code.

void sendmessage(char *);

void sendmessage(char * string)
{
putc(STX);
printf(string);
putc(ETX);
}

void main(void)
{
while(1)
{
sendmessage("Message test");
}
}

That is suppose do be very easy, with any normal compiler why it's doesn't work ?
___________________________
This message was ported from CCS's old forum
Original Post ID: 11154
R.J.Hamlett
Guest







Re: char * fonction parameter sendmessage(char *);
PostPosted: Fri Jan 31, 2003 7:16 am     Reply with quote

:=I try to make a fonction who receive a char pointer, and it's does'nt work, this is my code.
:=
:=void sendmessage(char *);
:=
:=void sendmessage(char * string)
:={
:= putc(STX);
:= printf(string);
:= putc(ETX);
:=}
:=
:=void main(void)
:={
:= while(1)
:= {
:= sendmessage("Message test");
:= }
:=}
:=
:=That is suppose do be very easy, with any normal compiler why it's does'nt work ?
:=
:=
The comment 'read the manual' applies...
Because of the architecture of the PIC, you can't have pointers to constants stored in ROM. The string if declared 'inline' like this, is stored as a constant table.
You can copy the string into a RAM array (in which case the code will work as given), or the code does have a 'cheat', where a function that expects a single character, will if called as:

function("string");

be called six times, with each character from the string in turn.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 11156
Alexandre Blais
Guest







Re: char * fonction parameter sendmessage(char *);
PostPosted: Fri Jan 31, 2003 9:20 am     Reply with quote

I have use Hi-tech picc and CC5X and this work very good like any other normal ansi c compiler. So theres any way to pass a string to a function this suppose to be a very basic thing.
Big limitation.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11160
Sherpa Doug
Guest







Re: char * fonction parameter sendmessage(char *);
PostPosted: Fri Jan 31, 2003 4:15 pm     Reply with quote

:=
:=I have use Hi-tech picc and CC5X and this work very good like any other normal ansi c compiler. So theres any way to pass a string to a function this suppose to be a very basic thing.
:=Big limitation.

I'll bet if you look at the code size you will find the other compilers go through some very painful gymnastics to use pointers to ROM on a PIC. It is not impossible, and Mr Hamlett gave you two ways it CAN be done. But the wizards who came up with the Harvard architecture the PIC is based on, decided long ago that such pointers SHOULD NOT be done.

I am just a lowly BSEE so I don't easily question the wizards.
___________________________
This message was ported from CCS's old forum
Original Post ID: 11173
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