View Single Post
Old May 25th, 2006, 5:58 AM   #10
bivhitscar
Hobbyist Programmer
 
bivhitscar's Avatar
 
Join Date: Oct 2005
Location: Melbourne, Australia
Posts: 126
Rep Power: 4 bivhitscar is on a distinguished road
Quote:
Originally Posted by Jimbo
Why not? It's a silly way of doing things, but what's stopping you?
Well, it can be done - but the compiler should throw up a warning about a comparison between different types; in this case, a pointer and an integer.
Hmm, it doesn't seem to throw a warning for my last case, but it does for this:

int main(int argc, char *argv[])
{
    char * ptr = NULL;
    char ch = '\0';
    
    ptr = &ch;
    
    if ( *ptr == NULL )
    {
         printf("null\n");
    }
    
    system("PAUSE");	
    return 0;
}

Does this mean it is valid to compare a pointer with '\0', but not a character variable with NULL? So, NULL is only for pointers - but pointers can be used with either comparison. Stupid discrepancies.

Quote:
Originally Posted by Jimbo
I wouldn't say that it's bad practice, as it really depends on the algorithm.
And yeh, hence my second edit.
__________________
it's ironic considerate rarity patron of love higher knowledge engulfs me...
bivhitscar is offline   Reply With Quote