Re: Printing a NULL pointer



junky_fellow@xxxxxxxxxxx wrote:

> Is there any way by which user can determine what is the internal
> representation for a NULL pointer ? I am asking this because,
> sometimes during debugging the memory dump is analysed. In that
> case it would be difficult to find it is a NULL pointer or not.

/* BEGIN new.c */

#include <stdio.h>

int main(void)
{
void *pointer = NULL;
size_t byte;

for (byte = 0; byte != sizeof pointer; ++byte) {
printf(
"byte %lu is 0x%u\n",
(long unsigned)byte,
(unsigned)((unsigned char *)&pointer)[byte]
);
}
puts(
"There may be more than one "
"representation for a null pointer."
);
return 0;
}

/* END new.c */

--
pete
.



Relevant Pages

  • Re: printf("%p ", (void *)0);
    ... A pointer to void is ... required to have the same representation as 'char *', ... > purposes of a pointer to void. ... and for precisely the same reasons. ...
    (comp.lang.c)
  • Re: ptr conversions and values
    ... >>> representation is a mapping, ... > Joining them in pairs is called mapping, ... Two pointer values are equivalent if they ... In case of no convenient pointer-integer conversion (on my imagined ...
    (comp.std.c)
  • Re: CPtrList - Please Help me understand
    ... object of type notice*, and you won't need to do casts at all. ... >Now although bp has a pointer to an object of type B (which we know because we created ... >compiler now happily does the assignment. ... >Generally, casting has no effect on the representation of a value, other than instructing ...
    (microsoft.public.vc.mfc)
  • Re: ptr conversions and values
    ... >>> Well, fortunately the standard says no such thing, and therefore I don't ... > A representation is a mapping from a bit pattern to a some target set. ... A pointer represents memory ...
    (comp.std.c)
  • Re: ptr conversions and values
    ... >> but once a pointer points to one thing, it may point to many things. ... >>> struct x pointer to a struct y pointer is undefined behaviour due to ... we cannot say they have the same representation. ... If for some values the conversion is not defined, ...
    (comp.std.c)