473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Default parameters in macros... Is it possible?

Hi all,

I am upgrading a kind of small logging framework. Until now, the
interface for logging messages takes only a format string, and a
variable argument list (in a similiar way as printf()). The interface
to the code that uses the logging facilites is through macros, i.e. one
ogf the macros looks like this:

#define LOG(fmtString, ...) GlobalLogger.LogToFile(fmtString"\n",
##__VA_ARGS__)

Now I am introducing message types, filtering etc, and need to add one
more parameter to the macros. Of course I can include that parameter in
the variable argument list, but it is good the varaible argument list
to follow the format string. So my question is: Is there a way to
implement the notion of default parameter in the macros, so the new
macros are compatible with the old code that uses them. Any ideas?

Regards
Alex

Apr 13 '06 #1
1 11703
avasilev wrote:
Hi all,

I am upgrading a kind of small logging framework. Until now, the
interface for logging messages takes only a format string, and a
variable argument list (in a similiar way as printf()). The interface
to the code that uses the logging facilites is through macros, i.e. one
ogf the macros looks like this:

#define LOG(fmtString, ...) GlobalLogger.LogToFile(fmtString"\n",
##__VA_ARGS__)

Now I am introducing message types, filtering etc, and need to add one
more parameter to the macros. Of course I can include that parameter in
the variable argument list, but it is good the varaible argument list
to follow the format string. So my question is: Is there a way to
implement the notion of default parameter in the macros, so the new
macros are compatible with the old code that uses them. Any ideas?

Regards
Alex


Currently, variable argument macros are not part of the C++ standard.
It is part of the C standard, and some compilers like GNU will let you
use variable argument macros in C++ code.

Check out the following logging library:
http://axter.com/ezlogger

The above library uses a temporary object to store some of the
parameters, and then uses the temporary object's methods to call a
variable argument function.
See following link for macro syntax:
http://axter.com/ezlogger/ezlogger__macros_8hpp.htm

Example:
#define EZDBGONLYLOGGERPRINT axter::ezlogger<>(__FILE__, __LINE__,
__FUNCTION__).cprint

To remove above logging from a release version of the code, you can use
the following method:
#define EZDBGONLYLOGGERPRINT if (1);else printf

Most compilers will compile away the above line complete from the
release version of the code.

This method is more portable then using variable argument macro.
----------------------------------------------------------------------------------------
David Maisonave
http://axter.com

Author of Axter's policy based smart pointers
(http://axter.com/smartptr)
Top ten member of C++ Expert Exchange:
http://www.experts-exchange.com/Cplusplus
----------------------------------------------------------------------------------------

Apr 13 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael Stembera | last post by:
I would like to use default parameters in nested templates but MS VC++ 7.1 chokes on it. Does anyone know how to fix the simple example below or if indeed it is possible? template <int N=7>...
2
by: Vic Y | last post by:
Hi, I am trying to call a user defined function(UDF) from a stored proc, using a default parameter in the called UDF (e.g. @bid_price_type int = 0 ). However the calling stored proc complains...
7
by: Vyssokih Max | last post by:
Hello! In C++, I can wrote: void Update(int count = 0) {...} and use it without parameters or with one parameter
8
by: cody | last post by:
Why doesn't C# allow default parameters for methods? An argument against I hear often is that the default parameters would have to be hardbaken into the assembly, but why? The Jit can take care of...
21
by: utab | last post by:
Hi there, Is there a way to convert a double value to a string. I know that there is fcvt() but I think this function is not a part of the standard library. I want sth from the standard if...
37
by: Bill Pursell | last post by:
I really like having the ability to specify parameter names when I call a function, and I've been tempted to do things like the following: foo ( (struct foo_args){.area = 5, .base=4}); but...
9
by: weirdwoolly | last post by:
Hopefully someone will be able to help. I have written a stored procedure in C++ called from a Java test harness to validate the graphic data types in C++ and their use. I have declared the...
74
by: Zytan | last post by:
I have a struct constructor to initialize all of my private (or public readonly) fields. There still exists the default constructor that sets them all to zero. Is there a way to remove the...
6
by: Mark | last post by:
I have a problem with a template class defined: // start matrix.h file template <class Tclass Matrix { public: Matrix() { // default constructor } Matrix(const Subscript rows, const...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.