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

Printf routine

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



Joined: 11 May 2006
Posts: 78

View user's profile Send private message

Printf routine
PostPosted: Fri Jul 18, 2008 7:11 am     Reply with quote

Hello all,

I have got to a point in my programming where I am writing a lot of printf statements, this is obviously using a lot of ROM and RAM.

I have now put the printf statement in a routine and i am passing the routine the string to print.

But I have a problem with passing the routine a string, i.e. the compiler doesnt like
Code:

void send_serial(serial_string)
{
      puts(serial_string);
}
.
.
.
.
send_serial("This is a test string");

Error "Attempt to create a pointer to a constant"

So I am forced to use:-
Code:

void send_serial(serial_string)
{
      puts(serial_string);
}
.
.
.
.

strcpy(serial_string, "This is a test string");
send_serial(serial_string);


My question is, would this save code space in the long run or is there another way of sending a string to a function?

TIA

sjharris
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Fri Jul 18, 2008 8:11 am     Reply with quote

To answer your question, No I don't think this will save code space in the long run. I believe that printf stores the strings in program memory. You could try to store them in the DATA EEPROM of the chip to save program memory.

In the old compilers 3.2xx you could just make a function that takes a char
and then when using the function, pass it a string. And the compiler does the
magic to call the function for every letter of the string.

Code:

void send_serial(char a)
{
      putc(a);
}
.
.
.
.
send_serial("This is a test string");


see C:\Program Files\PICC\Drivers\LCD.C
C:\Program Files\PICC\Examples\EX_LCDKB.C
Quote:
lcd_putc("\fReady...\n");



If there is formatting involved then use printf with a custom function.
see ccsc.chm fprintf/printf
printf(fname, cstring, values...) where fname is a function name to be used for outputting a single char
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