On Tue, 04 Nov 2014 20:05:55 -0500,
ag...@drrob1.com wrote:
>Still not clear to me. NULL pointer has to have a value; I'm assuming
A pointer has to have a value. (Pointers with automatic storage class
can be indeterminate but that is not relevant to this discussion.) One
of the values a pointer can have is NULL. (Any attempt to dereference
a NULL pointer, using either * or -> operators, results in undefined
behavior. A seg fault is one of the best manifestations of undefined
behavior because it immediately eliminates any delusions that the code
is working properly.)
>it's zero, as that is what gdb showed me. I know I can assign ch='\0'
NULL is a macro that is usually defined in C++ to be 0 (C tolerates
other definitions). You can test a pointer to see if its value is
NULL with expressions of the form
ptr == NULL
and
ptr != NULL
but that does not mean the bits that make up the pointer are all set
to 0. You normally don't care what the bit pattern is in a pointer
and if you do it is system specific and non-portable. It is the
compiler's job to generate the correct code so the two expressions
evaluate correctly regardless of the bit pattern.
>which is the same except for type.
Setting a char to '\0' has nothing to do with the value of a pointer.
>Is it possible for me to convert this 0 byte to an int for inspection?
You can convert the value of a pointer to an int with the appropriate
cast. It might be better to use intptr_t. In any case, I don't think
the result is guaranteed to be 0 if the pointer happens to be NULL.
But there is no need. The expressions above will always tell you if
the value is or is not NULL.
>I tried atoi and type casting, but I don't understand this well enough
>yet.
As noted, there is no need.
--
Remove del for email