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

printf questions

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



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

printf questions
PostPosted: Tue Jul 25, 2006 3:18 am     Reply with quote

I have do my litle code and now i want export it in lcd display .
my problem is that output of this assigns a lot of memory pic
example i have ;
if(A==0)
printf(lcd_putc,"\fWater press \n%4.2fBar",Buff/40.92);
if (A==1)
printf(lcd_putc,"\fTemperature \n%4.2fC",Buff/40.92);
if (A==2)
printf ( lcd_putc, "\f %05.0f RPM ", freq*60 );

ecc ..
there is a mode for global it ? because do out of memory pic .
i was try with atoi ,itoa funtions but is worse :(
sorry for my not good english
thanks.
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 10:42 am     Reply with quote

If your program is going to have a lot of printf() statements you might want to put the printf() in it's own routine and then have it called from other parts of the program. That way only one printf() will be taking up memory space.

Ronald
ferrarilib



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

PostPosted: Tue Jul 25, 2006 10:51 am     Reply with quote

thanks ronald !
i am doing so .
and %f4.2 ecc in eeprom so i cange format output with eeprom address thanks
ferrarilib



Joined: 11 Jun 2005
Posts: 38

View user's profile Send private message

PostPosted: Wed Jul 26, 2006 5:24 am     Reply with quote

now i have do one global functions but my problem now is cange format in sprintf()
example ;

char BUFFER[25];
char Format[]="\f %4.2";
char Format1[]="\f %s";
ecc..

sprintf(BUFFER,Format,Dati);

output only ;
\f %4.2
or
\f %s

not the data format :(
there is metode fot do this ?
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 26, 2006 6:21 am     Reply with quote

You can always write your own printf/sprintf
Ttelmah
Guest







PostPosted: Wed Jul 26, 2006 6:54 am     Reply with quote

There are two seperate 'big problems'. The first is that printing code is bulky. A 'generic' printf, would need to have the output routines to deal with all possible input format strings loaded, and would therefore be very large. CCS avoids this, by only loading the routines corresponding to the requested output forms.
The second problem though, is that CCS, does not support variable length argument lists. This is a basically 'essential' feature, to write your own printf. I suspect this is actually the core 'reason' why the CCS printf, is implemented the way it is, since as it is currently done, the compiler can decide during compilation, how many arguments there are, and code the actual function in each case, as if it has a fixed length argument list.
Realistically, if there are only a few choices, then the easiest solution, is to just have a system variable defining how you want a value printed, and then a subroutine, with a switch statement, based on this variable, and accepting the address of the value you want printed, selecting the required printf format.

Best Wishes
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Jul 26, 2006 7:06 am     Reply with quote

Ttelmah wrote:
There are two seperate 'big problems'. The first is that printing code is bulky. A 'generic' printf, would need to have the output routines to deal with all possible input format strings loaded, and would therefore be very large. CCS avoids this, by only loading the routines corresponding to the requested output forms.
The second problem though, is that CCS, does not support variable length argument lists. This is a basically 'essential' feature, to write your own printf. I suspect this is actually the core 'reason' why the CCS printf, is implemented the way it is, since as it is currently done, the compiler can decide during compilation, how many arguments there are, and code the actual function in each case, as if it has a fixed length argument list.
Realistically, if there are only a few choices, then the easiest solution, is to just have a system variable defining how you want a value printed, and then a subroutine, with a switch statement, based on this variable, and accepting the address of the value you want printed, selecting the required printf format.

Best Wishes


You can work around the variable arguments. See my scanf() code in the library. For just a few printf's, CCS's code would be smaller. But if the problem is that you have many printf's taking up way too much code, at some point it is worthwhile to write your own.
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