Liste des Groupes | Revenir à cl c |
David Brown <david.brown@hesbynett.no> writes:Yes, you are right - while "free(void ** p)" might often be feasible in practice (since on most implementations, pointers are the same size and representation) it would at a minimum rely on compilers being somewhat lax about accepting these conversions. Certainly it is not something that could be part of the standard.
[...]If you want a better signature for "free", then I would suggest "voidI'm not sure that would work. A void** argument means you need to pass
free(void ** p)" - that (to me) more naturally shows that the function
is freeing the pointer, while also greatly reducing the "use after
free" errors in C code by turning them into "dereferencing a null
pointer" errors which are more easily caught by many OS's.
a pointer to a void* object. If you've assigned the converted result of
malloc() to, say, an int* object, you don't have a void* object. (int*
and void* might not even have the same representation).
Some kind of generic function that takes a pointer to an object of any
object pointer type could work, but the language doesn't support that.
(C++ addressed this by making `new` and `delete` built-in operators
rather than library functions.)
Les messages affichés proviennent d'usenet.