?
Solved

How do I make a wrapper function for printf ?

Posted on 2004-08-01
2
Medium Priority
?
372 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month14 days, 4 hours left to enroll

801 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