C
Christian Bau
[email protected] (Wayne Throop) said:On the Nth hand, something like
p = malloc(sizeof *p);
is particularly handy, because you can change the type of p
without having to dive into the code everywhere. Better (IMO)
would be something like
p = (typeof *p)malloc(sizeof *p);
but I don't think that works.
If we go into things that are not C, then why not
allocate (p, 1);
with a new library function "allocate" which takes two arguments: An
lvalue p which must be a pointer to a complete type, and an integer. The
function would allocate space for as many objects as the integer
specifies and store the result in the pointer variable.
No chance to cast anything, so the whole argument would go away
(Even better if this comes together with a reallocate function that
returns a boolean upon success; using realloc is always a pain. )