Liste des Groupes | Revenir à cl c |
On 12/01/2025 11:22, Keith Thompson wrote:
>Michael S <already5chosen@yahoo.com> writes:>
[...]
>Tried to read the old discussion. Didn't understand much.>
But it strengthened my opinion: it's ridiculous. Standard would be way
better with this nonsense removed.
The function below should be guaranteed by standard to return 42.
int foo(void)
{
char* a = malloc(100);
if (!a) return 42;
char* b = a + 42;
free(a);
return b - a;
}
How exactly would that be useful?
>
The intent, I think, is to allow for implementations that perform
checking when loading a pointer value. It's possible that there
currently are no such implementations, but even so, how would
reading a free()d pointer value be useful?
>
I'd say that passing a pointer value to free() means you no longer care
about it.
What if, after the free(a), you have ...
>
char *b = malloc(100);
>
... and the old address of 'a' gets reused.
>
Could you then carry on using 'a'?
>
You'd be relying on chance, and it'd be terribly bad form ... but
would it be legal?
Les messages affichés proviennent d'usenet.