On Friday 22 April 2005 03:37, synthetoonz@bellsouth.net wrote:
From: Colin Carter
On Thursday 21 April 2005 22:31, Randall R Schulz wrote:
On Thursday 21 April 2005 02:48, Michael Stevens wrote:
In C++ it would seem that the 'const void * NULL = 0' definition would be a good thing as opposed to the literal '0' which Bjarne is recommending.
I used these routinely in my C++ work:
const void *NIL = 0; const char NUL = 0;
I would use a naked 0 in source code only where the context was actually integer, not pointer or character, in which case I'd use on of these.
How do you write that a pointer ptr is pointing nowhere?
If you want to know if a pointer is NULL, that is, not a valid pointer, you just compare the pointer. If you dereference the pointer (that's the * ) then you are examining what the pointer is pointing at.
Explicitly stated, if (pointer == NULL) /* The pointer must be NULL */
snip Thanks Synthetooz and Jerry. I usually see Jerry's notation, but am comfortable with, and actually prefer, the if( !pointer). Anyway, you are both really saying that the memory where pointer value is stored contains a full house of zeros and one just tests for zero. Which in turn means that I ought to be able to say pointer = 0; but I doubt if the C compiler would allow me to be so simple. (This assumes that in C one never wishes to access the value in location 0. A more invalid" address would be -1, but that would cause havoc with if(). ) pointer = &K; means pointer holds the address of K So I suppose, from your notes, I should write pointer = NULL; because wouldn't *pointer = NULL; imply that I am pointing to an (integer) whose value is zero? You can see that I am not that comfortable with C pointers. I can understand your if(...) notes, but I can't quite see how one is formally supposed to 'de-allocate' the pointer. Regards, Colin