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 disable if not in debug mode?

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








Printf disable if not in debug mode?
PostPosted: Wed Jan 21, 2009 10:49 am     Reply with quote

Hi

I have a lot of
Code:
printf("...");
statements in my code. The output is to RS232, I use the hardware com in my PIC.

Is it possible to make something smarter than:
Code:
if (debug) {printf("...");}


The debug bit is changed in the software therefore a solution with "define will not work.

Because it will take a lot of modification time to make it running.

Any hints?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 21, 2009 1:51 pm     Reply with quote

You could re-write your printf statements to re-direct the output to
your own output routine. In that routine, you could check your debug
flag, and if it's True, then call putc(). If not, then just return. The
character will be thrown away. (The whole string will be thrown away)
Guest








PostPosted: Wed Jan 21, 2009 3:46 pm     Reply with quote

Hi

As this?

Code:
void DebugPrint(char c){
 if (debug) {putc(c);}
}



(can't remember what the printf is, if printing to a function, anyway it dosen't matter for the ex.)
Code:
printf(DebugPrint,"Print Test:%u\r\n",i);


But then the cpu(PIC) still must run the hole printf process but nothing is sent out to RS232. The only time I save here is the RS232 timing?

Do I over look something?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 21, 2009 4:04 pm     Reply with quote

I thought your goal was to simply have output or not to have output.
I didn't know about your timing requirements.
Guest








PostPosted: Wed Jan 21, 2009 4:16 pm     Reply with quote

Hi

Thanks for your help:-)
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