473,612 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling function depending upon MACRO value

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
3 1561
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
"param" <dh******@gmail .com> wrote in message
news:11******** ************@o1 3g2000cwo.googl egroups.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
"Jim Langston" <ta*******@rock etmail.com> wrote in message
news:oE******** *****@fe06.lga. ..
: "param" <dh******@gmail .com> wrote in message
: news:11******** ************@o1 3g2000cwo.googl egroups.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
1464
by: iceColdFire | last post by:
Hi, Is there some way where I can call a function without explicitly making a function call... I need this in a scenario where a function is called say f(); and it automatically calls some logging functions, logA(),logB() etc... however these calls dont exist in f() body {}... Thanks,
6
4742
by: Allan Bruce | last post by:
Hi there, I am loading in a 3d object from file. The code I have works fine but it is very slow for objects with many vertices, i.e. >5000 I make use of the atoi function 3 times for each vertex, so am making a lot of them! I wish to make a macro to speed up execution. I know that the numbers will all be stored correctly in a char array in memory. I also know that each number will be >0 and I will limit the value to less then the max...
9
3369
by: simonmarkjones | last post by:
I want to call a function which does this when the next record button is pressed (calling it from before update) if textboxes are empty then Message box you must fill text box
19
4239
by: Ross A. Finlayson | last post by:
Hi, I hope you can help me understand the varargs facility. Say I am programming in ISO C including stdarg.h and I declare a function as so: void log_printf(const char* logfilename, const char* formatter, ...); Then, I want to call it as so:
4
1757
by: Miguel Dias Moura | last post by:
Hi, I just uploaded a web site and i am getting an error. I have a script which sends form values to an email using AspNetEmail. The script was working when i was calling the script like this: <asp:Button ID="Finish" runat="server" OnClick="sendEmail"> However, in this new web site version, when the button is pressed, to scripts are supose to run. So i replaced the button code with this:
1
2659
by: Sen K via .NET 247 | last post by:
(Type your message here) Hi, Any help is appreciated. I have a situation wherein i need to compact access db after somebusiness logic through VB.NET.I've written a function in VBA tocompact the database and i am calling that function in AccessMacro, and if i run that access macro in the backend, itsworking fine.But when i tried to call that access macro fromVB.NET code,i'm not getting any errors, but that macro is notworking. I'm calling...
5
4632
by: mike | last post by:
If I have a document like: <script> function mike_test() {alert('hi');} </script> <iframe src="blank.html" id="my_iframe1"> </iframe> and in blank.html I have:
4
1663
by: dis_is_eagle | last post by:
HI.In what circumstances we should use a macro and when we should use a function? If we use macro then will the size of the executable increase?Thanks for help. Eric
12
1548
by: Fabrice | last post by:
Hi, Lets say I want to define a generic macro to swap bytes in a integer: #define swapbytes(x) ... I have several implementation of the macros, one is generic C, the other one will be an optimized assembly version for a specific architecture. So I do something like that in swapbytes.h:
0
8114
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8422
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7044
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6081
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4047
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
1699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1414
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.