Posted Mar 19, 2008 22:27 UTC (Wed) by dw (subscriber, #12017)
In reply to: null pointers by vmole
Parent article: Who maintains dpkg?
"The idea of a "void *" being generic is that variables of type "void *" can store pointers of
any type, and pointers can be cast to void and then back to the original type without
information loss."
As far as I remember it is illegal to convert between void* and any function pointer type in
ANSI C; POSIX' specification of dlsym() actually relies on what is essentially a vendor
extension to work for function pointers.
Posted Mar 19, 2008 22:52 UTC (Wed) by vmole (guest, #111)
[Link]
Oops, you're correct about that. I just looked in Plauger and Brodie's "Standard C" (which is not the standard, but I think we can trust them), and they agree: it's *object* pointers that can be intraconverted with void pointers.
But the hilarious thing is this:
The types _pointer_to_char_, _pointer_to_signed_char_, _pointer_to_unsigned_char_, and _pointer_to_void_ all
share the same representation.
So "(void *) 0" is interchangeable with "(char *) 0", but not "0" or "(int *) 0".
A small nit-pick...
Posted Mar 19, 2008 23:15 UTC (Wed) by nix (subscriber, #2304)
[Link]
This is surely related to the aliasing rules, which also have a similar
special hole allowing aliasing of of void * and char *, but not of
pointers of any other distinct types.