Specific pointer -> generic pointer -> boolean (i.e. implicit compare to 0) seems not to work as expected.
void main() { char* p; char* q; char xdata* xp = NULL; bit fail = FALSE; // This fails. if ( p = xp ) { fail = TRUE; } // This is ok. if ( ( q = xp ) == NULL ) { fail = TRUE; } }
Jon, Thanks so much for this posting. It really hit home regarding the NULL value problem even after I had read the section on generic pointers and conversion. The issue to me is that during the comparison I am looking at the memory-type, which I do not care about. Here is a suggestion that might work.
char * var; if ((unsigned short) var == (unsigned short) NULL) {}
This will strip out the memory types on both sides and then a valid comparison can be made. What do you think? I'd probably do something like this:
#define ISNULL(x) (((unsigned) (void *) (x)) == 0) void * p; // gerneric pointer . . . if (ISNULL(p)) { // NULL pointer detected }
It would be worth you taking a look here: http://www.keil.com/update/_docs/releasenotes/c51v709.htm as there have been a number of bug fixes throughout version 7.x releases relating to comparisons between generic/far pointers and NULL. Stefan