I have defined a custom assert macro. This works fine for all other comparisons. However, I get the compiler error:
ISO C++ forbids comparison between pointer and integer
when using the macro shown below (DWASSERT) to compare pointers as in the code below.
#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;
}
While I can simply avoid using DWASSERT for this case, I am curious as to why this compiler error is generated.