The more I think about pointers, the more my head hurts.
From what I can tell, nothing in the standard guarantees that pointer
assignment preserves bit patterns.
Section 6.5.16.1, paragraph 2, states:
In simple assignment (=), the value of the right operand is
converted to the type of the assignment expression and replaces
the value stored in the object designated by the left operand.
Since we know that multiple bit patterns can represent the same "value",
it's possible that the following function could return a non-zero value.
int ptr_test(void)
{
char c;
void *p, *q;
p = &c;
q = p;
return memcmp(&p, &q, sizeof(void *));
}
Since I know you'll ask, I was thinking about implementing some simple
functions modeled after Win32's HeapAlloc, HeapFree, etc. A "heap" in
this case would just be a binary search tree, using the pointers
returned by malloc (or calloc or realloc) as keys.
This won't work, though, if I can't somehow compare pointers to
different objects, which rules out a simple comparison.
Am I missing something?
Thanks!
--
================================================== ======================
Ian Pilcher pi******@attbi.com
================================================== ======================