In said:
<quote>
"but since it points to void, what it points to can't be changed anyway."
</>
This is wrong. It's not because a pointer is void that the pointed data is
not accessible, at least indirectly.
A pointer to void cannot, by definition, point to any data. It is not
a data pointer. It merely contains an address with no data type attached.
If you want to access any data, you need first to either convert it or
to alias it with a pointer to character type.
The point is that the alias must be const too.
If there is such a point, your example doesn't reflect it.
char s[] = "Hello"; /* R/W data */
void const *p = s; /* not dereferencable. */
char *pa = p; /* Diagnostic */
char const *pb = p; /* Correct. Read only acces */
I can't see any pointer aliasing another pointer in your example. Are
you sure you know what you're talking about?
I came with the idea that 'aliasing' was the result of more than one pointer
pointing to the same location. If you have a better definition, I'd be glad
to ear it.
You were talking about aliasing a pointer, not about aliasing the
pointed to data. See the underlined text above. As it happens, void
pointers can be aliased with character pointers, because they have the
same representation. A concrete example is left as an exercise to the
reader.
Hence, in my example, 'pa' and 'pb' are aliasing 'p'.
Nope. All three are aliasing the pointed data, when dereferenced.
My wording might be incorrect; correctness welcome.
It's your job to check your terminology, as this is not an
English-specific issue.
Just as evil as making p a pointer to const in the first place.
Hehe! Abusive typecast users will burn in hell ;-)
Except that there is no abuse here. The abuse was in using a pointer to
const in the first place! ;-)
Here's an example of abusive pointer casting:
const char *s = "Hello";
void const *p = s;
char *pa = (char *)p;
Can you understand the difference?
Try avoiding schematic/religious thinking and you'll become a much
better C programmer.
Dan