#define MacroName(x) ..
#define MacroName(x, y) ..
Overloading macros - Can anyone do it??
Does anyone have any "tricks" that can enable a macro to be overloaded like so?
I forgot to add.. I cannot #define the macro name to be a name of a overloaded function because I need to paste the __FILE__, __LINE__ macro in the caller
ie. can''t do this
ie. can''t do this
void FunctionName(int x);void FunctionName(int x, int y);#define MACRO Function_NameMACRO(10);MACRO(10, 20);
Short answer: Can''t be done. And they can''t be recursive, either.
Use instead, for example, function with varargs (similar to printf), or inline functions pretending to be macros.
Use instead, for example, function with varargs (similar to printf), or inline functions pretending to be macros.
~~~ "'impossible' is a word in the dictonary of fools" --Napoleon
Definitely use inline functions for this. There is no reason not too, in this case.
inline MacroName(int x) { // do whatever; }
inline MacroName(int x, int y) { // do whatever; }
What''s cool is that now you will get type-checking when compiling.
Dire Wolf
direwolf@digitalfiends.com
inline MacroName(int x) { // do whatever; }
inline MacroName(int x, int y) { // do whatever; }
What''s cool is that now you will get type-checking when compiling.
Dire Wolf
direwolf@digitalfiends.com
[email=direwolf@digitalfiends.com]Dire Wolf[/email]
www.digitalfiends.com
www.digitalfiends.com
quote: Original post by Dire.Wolf
Definitely use inline functions for this. There is no reason not too, in this case.
Can''t use inlines because I need to paste the __FILE__ and __LINE__ macro from the caller. If I use an inline function, the macros point to the inline function, not the caller.
What I want to do is to replace the assert macro but "overload" it to take different # of arguments.
If you want this for an assert that takes a description and one that doesn''t, you can do this:
assert(Condition && "Description");
Using the same assert that would do this:
assert(Condition);
I think this works..
assert(Condition && "Description");
Using the same assert that would do this:
assert(Condition);
I think this works..
That is still the 1 parameter passed to the macro..I want a macro that can take a variable # of arguments..
I guess it can''t be done..
I guess it can''t be done..
Manual name mangling
#define 1argMacroName(x)
#define 2argMacroName(x, y)
Magmai Kai Holmlor
- The disgruntled & disillusioned
#define 1argMacroName(x)
#define 2argMacroName(x, y)
Magmai Kai Holmlor
- The disgruntled & disillusioned
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
quote: Original post by Magmai Kai Holmlor
Manual name mangling
#define 1argMacroName(x)
#define 2argMacroName(x, y)
That''s what I don''t want to do..overlitter it with macros.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement