|
|
View previous topic :: View next topic |
Author |
Message |
Alexandre Blais Guest
|
char * function parameter sendmessage(char *); |
Posted: Fri Jan 31, 2003 7:02 am |
|
|
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 *); |
Posted: Fri Jan 31, 2003 7:16 am |
|
|
:=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 *); |
Posted: Fri Jan 31, 2003 9:20 am |
|
|
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 *); |
Posted: Fri Jan 31, 2003 4:15 pm |
|
|
:=
:=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 |
|
|
|
|
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
|