Deutsch English Français Italiano |
<v8jp3f$321h8$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!.POSTED!not-for-mail From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> 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: Fri, 2 Aug 2024 16:11:43 -0700 Organization: A noiseless patient Spider Lines: 53 Message-ID: <v8jp3f$321h8$1@dont-email.me> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Sat, 03 Aug 2024 01:11:43 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c5d5c7fe7b787c73b28f56e08a59c030"; logging-data="3212840"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vxaWicO5up8ofvYPxH/jZQFzHT57glKc=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:mSs/PdaYQQYZjbwXnYFTiHPGSqU= In-Reply-To: <87le1ed0dl.fsf@bsb.me.uk> Content-Language: en-US Bytes: 2951 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? void foo(struct foobar const* const self) { //self is there... Do not mutate it! //Please for self is "special"? } > >> ;^) > > 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. Some people did not seem to like it very much, even though its was just me doing my thing. I can adapt rather quickly.