|
|
|
|
|
by jcranmer
2117 days ago
|
|
My gut instinct is as follows: void *x = malloc(...);
void *y = malloc(...);
assert(x != y); // standard guarantees this [1]
Yet it's fairly reasonable that: void *x = malloc(...);
free(x);
void *y = malloc(...); // malloc reused x's allocation here.
So, in effect, guaranteeing that the results of two mallocs can never alias each other, while allowing the implementation to reuse freed memory, requires semantically adjusting the value of a pointer to a unique, unaddressable value.[1] I think, but I'm not sure which versions of C/C++ added this guarantee |
|
It seems like they could have just said: malloc won't give you a pointer that overlaps with the storage of any live malloc'd object. Such a malloc is implementable without too much trouble. But instead, they gave a stronger guarantee--that all malloc'd pointers would be "unique". It would be unboundedly burdensome on the implementation to meet this property, so what do they do? Update the standard to offer the achievable guarantee? No! They add a new rule, ensuring that it's impossible to observe that the stronger guarantee is not met without doing something "illegal". Instead of getting their act together, they have elected to punish whistleblowers.