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 connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <82cc9501de86336cdef9fe610bce8e75238fb679@i2pn2.org>
Deutsch   English   Français   Italiano  
<82cc9501de86336cdef9fe610bce8e75238fb679@i2pn2.org>

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

Path: ...!weretis.net!feeder9.news.weretis.net!news.nk.ca!rocksolid2!i2pn2.org!.POSTED!not-for-mail
From: Richard Damon <richard@damon-family.org>
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 14:42:08 -0400
Organization: i2pn2 (i2pn.org)
Message-ID: <82cc9501de86336cdef9fe610bce8e75238fb679@i2pn2.org>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 2 Aug 2024 18:42:09 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="1215790"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
X-Spam-Checker-Version: SpamAssassin 4.0.0
In-Reply-To: <87v80ig4vt.fsf@nosuchdomain.example.com>
Content-Language: en-US
Bytes: 2966
Lines: 41

On 8/2/24 2:24 PM, Keith Thompson wrote:
> Richard Harnden <richard.nospam@gmail.invalid> 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.

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.

Of course, implementations would still be free to accept such code, and 
maybe even not even warn about it in non-pedantic mode, but making it 
part of the Standard would be a step to cleaning this up.