
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.93 KB | hits: 25 | expires: Never
C : Compiler Error While Comparing Pointers using Macros
ISO C++ forbids comparison between pointer and integer
#define DWASSERT(condition,printstatement) if(!condition){ printf(printstatement); assert(condition); }
#include <stdio.h>
int main()
{
int target = 0;
int* ptr1 = ⌖
int* ptr2 = ⌖
//Normal comparison works fine
if(ptr1 == ptr2)
printf("Equal");
//Comparison using Macro generates compiler
//error on the next line
DWASSERT(ptr1 == ptr2, "Pointers not equal!n");
return 0;
}
#define DWASSERT(condition,printstatement) if(!(condition)){ printf...
if(!condition)
if(! (condition) )
#define DWASSERT(condition,printstatement) if(!(condition)){ printf(printstatement); assert(condition); }
if (!ptr1 == ptr2) { ... }
if ((!ptr1) == ptr2) { ... }
int i = -1;
DWASSERT(++i, "will I assert?");
DWASSERT((ptr==ptr2), "Pointers not equal!n");