Printing values in DEBUG mode : define « Development « C++ Tutorial






#include <iostream>
 #define DEBUG
 
 #ifndef DEBUG
 #define PRINT(x)
 #else
 #define PRINT(x) std::cout << #x << ":\t" << x << std::endl;
 #endif
 
 int main()
 {
     int x = 5;
     long y = 78l;
     PRINT(x);
     
     for (int i = 0; i < x; i++)
     {
         PRINT(i);
     }
 
     PRINT (y);
     PRINT("Hi.");
     int *px = &x;
     PRINT(px);
     PRINT (*px);
     return 0;
 }
x:      5
i:      0
i:      1
i:      2
i:      3
i:      4
y:      78
Hi.":  Hi.
px:     0x22ff74
*px:    5








5.16.define
5.16.1.ASSERTS
5.16.2.function macro of get the max value number
5.16.3.Using parentheses in macros.
5.16.4.Using inline rather than a macro.
5.16.5.A simple assert() macro.
5.16.6.Printing values in DEBUG mode