Solved

How do I make a wrapper function for printf ?

Posted on 2004-08-01
2
324 Views
Last Modified: 2012-06-27
Hi,

I wish to add a wrapper function for printf, to allow multiple debug levels for my program. For example, I could pass it "-v 5" to be very verbose, or "-v 0" to print nothing at all.

The prototype function for printf is:

int printf (const char *format, ...);

How would I make my own function, my_printf, that takes into account the verbosity setting, and calls the real printf?
0
Comment
Question by:Risky101
2 Comments
 
LVL 23

Accepted Solution

by:
brettmjohnson earned 125 total points
ID: 11688694
To write a wrapper to printf, you will want to us va_list, va_arg, va_start... described here:
http://www.opengroup.org/onlinepubs/009695399/basedefs/stdarg.h.html


However, when faced with the same problem many years ago, I chose to actually
write a wrapper macro rather than function.  This helped performance by avoiding
the function/call return overhead for messages that would be discarded at the
current verbosity level.

0
 

Author Comment

by:Risky101
ID: 11689390
One word: brilliant! Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Boot Linux vm into a menu system 2 76
null coming in rpm name 3 58
Linux 10 106
updating the repos in yum 4 107
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now