Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I make a wrapper function for printf ?

Posted on 2004-08-01
2
Medium Priority
?
400 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 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…

885 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