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

Simple C char* question, old C hacks please help!

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



Joined: 15 Jun 2004
Posts: 21
Location: Nottingham UK

View user's profile Send private message

Simple C char* question, old C hacks please help!
PostPosted: Wed Jun 16, 2004 7:01 am     Reply with quote

Hi
Well, I'm up and running with the CCS compiler, and its nicer (so far) than the Hi-Tech one. But I seem to be forgetting my C (I'm a C# hack these days...).

I have the following:

void SendMessage(char* msg)
{
printf(msg);
putc(10);
putch(13);
}


Calling this like so:
SendMessage("A test message");
results in garbage being sent down the RS232.

Calling like so:
char temp[100];
strcpy(temp, "A test message");
SendMessage(temp);
works just fine.

Anyone know why the first instance fails?

Its an 877A using the PICDEM2 and ICD2

TIA!
Ttelmah
Guest







Re: Simple C char* question, old C hacks please help!
PostPosted: Wed Jun 16, 2004 8:07 am     Reply with quote

Gizz wrote:
Hi
Well, I'm up and running with the CCS compiler, and its nicer (so far) than the Hi-Tech one. But I seem to be forgetting my C (I'm a C# hack these days...).

I have the following:

void SendMessage(char* msg)
{
printf(msg);
putc(10);
putch(13);
}


Calling this like so:
SendMessage("A test message");
results in garbage being sent down the RS232.

Calling like so:
char temp[100];
strcpy(temp, "A test message");
SendMessage(temp);
works just fine.

Anyone know why the first instance fails?

Its an 877A using the PICDEM2 and ICD2

TIA!

Probably one of the most common "FAQ's" for the CCS compiler. It does not support pointers to constant strings (this is in the manual)...
The second version, copies the constant string from ROM to RAM, and this can then be sent normally.
A search through the forum, looking for comments like 'pointers to ROM', will find some of the thousands of posts about this.

Best Wishes
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Wed Jun 16, 2004 9:49 am     Reply with quote

Oh, I see it's another one of your rude RTFM replies, Ttelmah!

(big time just kidding!!!! - I couldn't resist)

- SteveS
Gizz



Joined: 15 Jun 2004
Posts: 21
Location: Nottingham UK

View user's profile Send private message

PostPosted: Wed Jun 16, 2004 9:55 am     Reply with quote

OK, thanks, if I had a FM to FR I would! LOL!
Guest








Try this...
PostPosted: Wed Jun 16, 2004 10:39 am     Reply with quote

As it's just a constant message, you could use

puts( " this is a message" );

Hans W
Guest








PostPosted: Wed Jun 16, 2004 8:26 pm     Reply with quote

Quote:


void SendMessage(char* msg)
{
printf(msg);
putc(10);
putch(13);
}


Calling this like so:
SendMessage("A test message");
results in garbage being sent down the RS232.



Sounds like a job for the C preprocessor. A macro will behave like an inline function, and the compiler will generate the appropriate code for the context.
Ttelmah
Guest







PostPosted: Thu Jun 17, 2004 10:57 am     Reply with quote

Gizz wrote:
OK, thanks, if I had a FM to FR I would! LOL!

The 'FM', is on the web...

Best Wishes Smile
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Thu Jun 17, 2004 5:46 pm     Reply with quote

Here it is: FM Very Happy
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