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

code size, putc() vs printf()

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







code size, putc() vs printf()
PostPosted: Fri Mar 07, 2003 3:09 pm     Reply with quote

gents,

consider this example short snippet:

#use rs232(baud=9600,xmit=PIN_DEBUG_TX,rcv=PIN_DEBUG_RX,errors,stream=L
CD)

void lcd_putc(char c) {
fputc(c,LCD);
}

i have noticed some code size difference between the following:

lcd_putc("abcdef");
vs.
printf(lcd_putc,"abcdef");

i realize that the latter is required for more complex printing tasks (e.g. parameter/variable substitution). BUT, for this example, with a "constant" string passed, should these two lines result in the same number of instructions?

thanks and regards
___________________________
This message was ported from CCS's old forum
Original Post ID: 12465
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: code size, putc() vs printf()
PostPosted: Fri Mar 07, 2003 6:09 pm     Reply with quote

:=i have noticed some code size difference between the following:
:=
:=lcd_putc("abcdef");
:=vs.
:=printf(lcd_putc,"abcdef");
:=
:=i realize that the latter is required for more complex printing tasks (e.g. parameter/variable substitution). BUT, for this example, with a "constant" string passed, should these two lines result in the same number of instructions?
-------------------------------------------------------

Use a different string for each test. If you use the
same string for each test, the compiler optimizes the
code, and generates only one set of "character fetch"
code. See the code below.

With the following code, the ROM usage is very nearly
the same. The compiler uses a different method to
determine the end of the strings -- for lcd_putc(),
it looks for a string terminator (0x00) but for printf(),
it counts up 6 chars. With PCM vs. 3.146 on a 16F877,
the difference in ROM usage is only 1 location, between
the two methods.

<PRE>
#include "c:\Program Files\Picc\Devices\16F877.h"
#fuses HS, NOWDT, NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS, stream=LCD)
<BR>
void lcd_putc(char c)
{
fputc(c,LCD);
}
<BR>
//====================================================
<BR>
void main()
{
<BR>
lcd_putc("abcdef");
<BR>
printf(lcd_putc,"ABCDEF"); // This is a different string
<BR>
while(1);
}
</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12474
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