Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Beginner
Apr 23, 2001



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Using MACRO Definitions

By using MACRO definitions, you can easily write lines of code that are only included in Debug versions and not in Release versions. For instance, if you create a function 'MyLog(x,y)' that writes debugging information to a file you can define a macro such as:
#ifdef DEBUG
#define LOG(a,b)   MyLog(a,b);
#define LOG(a,b)

Using conditional compilation, you can remove the 'MyLog' code from your Release version. However, in case of logging, you want to pass a variable amount of parameters most of the time. In this case the macro definition mentioned above doesn't work. Nevertheless, there is a nice workaround. The solution is to redefine the macro as:
#ifdef DEBUG
#define LOG(a)   MyLog a;
#define LOG(a)

In your code you should use it as:
LOG ((a,b,c))
LOG ((a,b,c,d,e))

By putting the parameters between double brackets, you can pass a variable amount of parameters to your macro.
Dominique Bijnens
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date