Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
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, 12 Aug 2024 08:27:04 -0700
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <86wmkl7odz.fsf@linuxsc.com>
References: <20240801174026.00002cda@yahoo.com> <87zfpvfdk4.fsf@nosuchdomain.example.com> <87v80ig4vt.fsf@nosuchdomain.example.com> <82cc9501de86336cdef9fe610bce8e75238fb679@i2pn2.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Mon, 12 Aug 2024 17:27:04 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f42e4005105099d89c60a754521770ce";
logging-data="3530086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19d+dvG9UGkVd41ry5U3Fjf3gPq/mgzXg0="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:iKRGBUvrl4zpT0oyv6+CRQ+oibs=
sha1:fD3sJn5HOShPkmcmHrVFlBjh91E=
Bytes: 3340
Richard Damon writes:
> On 8/2/24 2:24 PM, Keith Thompson wrote:
>
>> Richard Harnden writes:
>> [...]
>>
>>> Is there any reason not to always write ...
>>>
>>> static const char *s = "hello, world";
>>>
>>> ... ?
>>>
>>> You get all the warnings for free that way.
>>
>> The "static", if this is at block scope, specifies that the pointer
>> object, not the array object, has static storage duration. If it's at
>> file scope it specifies that the name "s" is not visible to other
>> translation units. Either way, use it if that's what you want, don't
>> use it if it isn't.
>>
>> There's no good reason not to use "const". (If string literal objects
>> were const, you'd have to use "const" here.)
>>
>> If you also want the pointer to be const, you can write:
>>
>> const char *const s = "hello, world";
>
> The one good reason to not make it const is that if you are passing it
> to functions that take (non-const) char* parameters that don't
> actually change that parameters contents.
Right.
> These may still exist in legacy code since so far nothing has required
> them to change.
>
> Perhaps it is getting to the point that the language needs to abandon
> support for that ancient code, and force "const correctness" (which I
> admit some will call const-pollution) onto code, first with a formal
> deprecation period, where implementations are strongly suggested to
> make the violation of the rule a warning, and then later changing the
> type of string constants.
Given the widespread availability of compiler options to treat
string literals as being const-qualified, it seems better to
leave the language alone and have people use those options as
they see fit. Making existing programs that have worked fine
for years become non-conforming is a heavy and unnecessary
burden, with an ROI that is at best very small and more likely
negative.