Deutsch   English   Français   Italiano  
<vm0s3p$17mss$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Richard Harnden <richard.nospam@gmail.invalid>
Newsgroups: comp.lang.c
Subject: Re: So You Think You Can Const?
Date: Sun, 12 Jan 2025 16:54:17 +0000
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <vm0s3p$17mss$1@dont-email.me>
References: <vljvh3$27msl$1@dont-email.me> <vlma9m$2s5e5$1@dont-email.me>
 <vlo0cm$2dkpd$9@dont-email.me> <vlqd4j$3s4ai$1@dont-email.me>
 <874j27qfp7.fsf@nosuchdomain.example.com> <20250110122353.00005377@yahoo.com>
 <vlr8if$17rn$1@dont-email.me> <20250112130744.00000118@yahoo.com>
 <87cygsjmyr.fsf@nosuchdomain.example.com>
Reply-To: nospam.harnden@invalid.com
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 12 Jan 2025 17:54:18 +0100 (CET)
Injection-Info: dont-email.me; posting-host="45409698036b6be1b007731fb6ef2716";
	logging-data="1301404"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19KEZb/2/DQvFHvSI00CwnXiFM+SUeULSo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bPYKGVU35UoggsRIodX68GQxHVE=
In-Reply-To: <87cygsjmyr.fsf@nosuchdomain.example.com>
Content-Language: en-GB
Bytes: 2481

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?