Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > preprocessor optional / default function argument

Reply
Thread Tools

preprocessor optional / default function argument

 
 
Philipp Kraus
Guest
Posts: n/a
 
      06-02-2013
Hello,

I need a little bit help with this problem:
I would like to create a preprocessor function FUNC with an optional argument:

#define FUNC callme(__FUNCTION__);
#define FUNC(name) callme(name);

callme is a C++ function, so if the user is run

FUNC
the parameter of callme should be the function name and
if the user call
FUNC("test")
the function callme should get the parameter "test".

How can I do this with no and one argument?

Thanks a lot

Phil

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      06-03-2013
On 6/2/2013 1:45 PM, Philipp Kraus wrote:
> Hello,
>
> I need a little bit help with this problem:
> I would like to create a preprocessor function FUNC with an optional
> argument:
>
> #define FUNC callme(__FUNCTION__);
> #define FUNC(name) callme(name);
>
> callme is a C++ function, so if the user is run
>
> FUNC
> the parameter of callme should be the function name and
> if the user call
> FUNC("test")
> the function callme should get the parameter "test".
>
> How can I do this with no and one argument?


There is probably a solution for this more elegant, but why not have two
separate macros?

#define FUNCFUNC callme(__FUNCTION__)
#define FUNC(str) callme(str)

Since the user is going to differenciate them anyway, four characters
are not going to make the weather:

...
FUNCFUNC; // for a call with __FUNCTION__

...
FUNC("test"); // for a call with "test"

.. And I strongly recommend not to include the semicolon as part of the
macro. That way you could use the macro where an expression is expected.

V
--
I do not respond to top-posted replies, please don't ask
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Variable argument function as a parameter of a variable argument function AikidoGuy C Programming 11 11-21-2011 10:43 PM
How to declare a function argument as optional? Pushkar Prasad C Programming 16 02-07-2011 07:41 PM
function argument dependent on another function argument? Reckoner Python 11 01-19-2009 03:31 AM
Compiler error occurred when try to use a flexible template expression in preprocessor definesCompiler error occurred when try to use a flexible template expression in preprocessor defines snnn C++ 6 03-14-2005 04:09 PM
preprocessor, token concatenation, no valid preprocessor token Cronus C++ 1 07-14-2004 11:10 PM



Advertisments