By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 801 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

Calling function depending upon MACRO value

P: n/a
Hi,

I need to write a MACRO which helps to call different functions
depending upon it's value say On or OFF. If its' value is ON the
function1 should get called and if value is OFF function2 gets called .

It's like same as assert gets executed when NDEBUG is not defined at
the start of code. If NDEBUG is defined assert doesn't gets called at
all.

Thanks
dhesi

Feb 22 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
param wrote:
Hi,

I need to write a MACRO
Are you sure?
which helps to call different functions
depending upon it's value say On or OFF. If its' value is ON the
function1 should get called and if value is OFF function2 gets called .
If you must use a macro, hide it's details behind a function call if
possible, making the macro merely an implementation detail.
It's like same as assert gets executed when NDEBUG is not defined at
the start of code. If NDEBUG is defined assert doesn't gets called at
all.


Can you provide an example of the functions you need to call?

Ben Pope
--
I'm not just a number. To many, I'm known as a string...
Feb 22 '06 #2

P: n/a
"param" <dh******@gmail.com> wrote in message
news:11********************@o13g2000cwo.googlegrou ps.com...
Hi,

I need to write a MACRO which helps to call different functions
depending upon it's value say On or OFF. If its' value is ON the
function1 should get called and if value is OFF function2 gets called .

It's like same as assert gets executed when NDEBUG is not defined at
the start of code. If NDEBUG is defined assert doesn't gets called at
all.

Thanks
dhesi


#define RUNTEST

#ifdef RUNTEST
#define Func(x) MyFunc(x)
#else
#define Func(x) {}
#endif

Truth be told, however, you should avoid uses of macros whenever possible.
Feb 23 '06 #3

P: n/a
"Jim Langston" <ta*******@rocketmail.com> wrote in message
news:oE*************@fe06.lga...
: "param" <dh******@gmail.com> wrote in message
: news:11********************@o13g2000cwo.googlegrou ps.com...
: > Hi,
: >
: > I need to write a MACRO which helps to call different functions
: > depending upon it's value say On or OFF. If its' value is ON the
: > function1 should get called and if value is OFF function2 gets called
..
: >
: > It's like same as assert gets executed when NDEBUG is not defined at
: > the start of code. If NDEBUG is defined assert doesn't gets called at
: > all.
: >
: > Thanks
: > dhesi
:
: #define RUNTEST
:
: #ifdef RUNTEST
: #define Func(x) MyFunc(x)
: #else
: #define Func(x) {}

The latter won't work properly with code such as:
if(test)
Func();
else
OtherStuff();
A classic 'no-op' function macro substitution is:
#define Func(x) ((void)0)
[ or the more general: do{ /*whatever*/ }while(0) ]

: #endif

:
: Truth be told, however, you should avoid uses of macros whenever
possible.

Yes!
Regards,
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Feb 23 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.