Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" 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: Sun, 4 Aug 2024 19:38:24 -0700 Organization: A noiseless patient Spider Lines: 78 Message-ID: References: <20240801174026.00002cda@yahoo.com> <87zfpvfdk4.fsf@nosuchdomain.example.com> <87v80ig4vt.fsf@nosuchdomain.example.com> <87le1ed0dl.fsf@bsb.me.uk> <875xsfdbhf.fsf@bsb.me.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 05 Aug 2024 04:38:25 +0200 (CEST) Injection-Info: dont-email.me; posting-host="8fb2bf3bc0b69bac1b2db0bf88076279"; logging-data="508254"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pjFr8LZ+96NdE+YmRnxQlCg+r8lf55nk=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:zC0NzLK+t77GV5qb6mxABk7ar2E= Content-Language: en-US In-Reply-To: Bytes: 3828 On 8/4/2024 7:37 PM, Chris M. Thomasson wrote: > On 8/4/2024 6:06 PM, Ben Bacarisse wrote: >> "Chris M. Thomasson" writes: >> >>> On 8/2/2024 3:29 PM, Ben Bacarisse wrote: >>>> "Chris M. Thomasson" 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 >>>>> >>>>> >>>>> 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 > } > > > Perhaps give the function a name... ;^) To write the declaration with names and the const access I want, so: extern void foobar(void const* const ptr); void foobar(void const* const ptr) { // ptr is a const pointer to a const void }