Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 0.93 KB  |  hits: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. C  : Compiler Error While Comparing Pointers using Macros
  2. ISO C++ forbids comparison between pointer and integer
  3.        
  4. #define DWASSERT(condition,printstatement)  if(!condition){ printf(printstatement); assert(condition); }
  5.  
  6. #include <stdio.h>
  7.  
  8. int main()
  9. {
  10.     int target = 0;
  11.     int* ptr1 = &target;
  12.     int* ptr2 = &target;
  13.  
  14.     //Normal comparison works fine
  15.     if(ptr1 == ptr2)
  16.         printf("Equal");
  17.  
  18.     //Comparison using Macro generates compiler
  19.     //error on the next line
  20.     DWASSERT(ptr1 == ptr2, "Pointers not equal!n");
  21.     return 0;
  22. }
  23.        
  24. #define DWASSERT(condition,printstatement)  if(!(condition)){ printf...
  25.        
  26. if(!condition)
  27.        
  28. if(! (condition) )
  29.        
  30. #define DWASSERT(condition,printstatement)  if(!(condition)){ printf(printstatement); assert(condition); }
  31.        
  32. if (!ptr1 == ptr2) { ... }
  33.        
  34. if ((!ptr1) == ptr2) { ... }
  35.        
  36. int i = -1;
  37.  
  38. DWASSERT(++i, "will I assert?");
  39.        
  40. DWASSERT((ptr==ptr2), "Pointers not equal!n");