Deutsch   English   Français   Italiano  
<87ttfzb5ar.fsf@bsb.me.uk>

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

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Ben Bacarisse <ben@bsb.me.uk>
Newsgroups: comp.lang.c
Subject: Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?
Date: Mon, 05 Aug 2024 12:03:08 +0100
Organization: A noiseless patient Spider
Lines: 65
Message-ID: <87ttfzb5ar.fsf@bsb.me.uk>
References: <IoGcndcJ1Zm83zb7nZ2dnZfqnPWdnZ2d@brightview.co.uk>
	<20240801174026.00002cda@yahoo.com> <v8gi7i$29iu1$1@dont-email.me>
	<slrnvaorkl.34j6.candycanearter07@candydeb.host.invalid>
	<87zfpvfdk4.fsf@nosuchdomain.example.com>
	<v8ii17$2q5p1$1@dont-email.me>
	<87v80ig4vt.fsf@nosuchdomain.example.com>
	<v8jbvj$2vat1$1@dont-email.me> <87le1ed0dl.fsf@bsb.me.uk>
	<v8jp3f$321h8$1@dont-email.me> <875xsfdbhf.fsf@bsb.me.uk>
	<v8pdsn$fgau$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Mon, 05 Aug 2024 13:03:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="d2414c6952e13c70edf3b01ba5b91a78";
	logging-data="686701"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19b3hqDGWgUgeEHoFCCLcrTixMS09uOUpU="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:6hdNNyjo4ECuH8GZ+0xgBSeWOss=
	sha1:CnPUudl9fEjimqstzc7Hw89up1I=
X-BSB-Auth: 1.943d9e33baf5d7771c2b.20240805120308BST.87ttfzb5ar.fsf@bsb.me.uk
Bytes: 3663

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:

> On 8/4/2024 6:06 PM, Ben Bacarisse wrote:
>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>> 
>>> On 8/2/2024 3:29 PM, Ben Bacarisse wrote:
>>>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>>>
>>>>> For some reason I had a sort of a habit wrt const pointers:
>>>>>
>>>>> (experimental code, no ads, raw text...)
>>>>> https://pastebin.com/raw/f52a443b1
>>>>>
>>>>> ________________________________
>>>>> /* Interfaces
>>>>> ____________________________________________________________________*/
>>>>> #include <stddef.h>
>>>>>
>>>>>
>>>>> struct object_prv_vtable {
>>>>>     int (*fp_destroy) (void* const);
>>>>> };
>>>>>
>>>>>
>>>>> struct device_prv_vtable {
>>>>>     int (*fp_read) (void* const, void*, size_t);
>>>>>     int (*fp_write) (void* const, void const*, size_t);
>>>>> };
>>>> Why?  It seems like an arbitrary choice to const qualify some pointer
>>>> types and some pointed-to types (but never both).
>>>
>>> I just wanted to get the point across that the first parameter, aka, akin
>>> to "this" in C++ is a const pointer. Shall not be modified in any way shape
>>> or form. It is as it is, so to speak:
>>>
>>> void foo(struct foobar const* const self);
>>>
>>> constant pointer to a constant foobar, fair enough?
>> No.  If you intended a const pointer to const object why didn't you
>> write that?  My point was that the consts seems to be scattered about
>> without any apparent logic and you've not explained why.
>> 
>>>>> ;^)
>>>> Does the wink mean I should not take what you write seriously?  If so,
>>>> please ignore my question.
>>>
>>> The wink was meant to show my habit in basically a jestful sort of
>>> way.
>> Your habit of what?
>
> To write the declaration with names and the const access I want, so:
>
> extern void (void const* const ptr);
>
> void (void const* const ptr)
> {
>    // ptr is a const pointer to a const void
> }

I don't think you are following what I'm, saying.  If you think there
might be some value in finding out, you could as a few questions.  I
won't say it again ;-)

-- 
Ben.