Path: ...!news.nobody.at!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 14:38:36 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <86plqd2zhf.fsf@linuxsc.com>
References: <20240801174026.00002cda@yahoo.com> <87zfpvfdk4.fsf@nosuchdomain.example.com> <87v80ig4vt.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Date: Mon, 12 Aug 2024 23:38:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="f42e4005105099d89c60a754521770ce";
logging-data="3643568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+rZVwWdHP10FgxzA6XFz17Fsdy4Af9ht4="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:oS838adTom89XqqNbg2LqNgMKGc=
sha1:9M3hkfHr0MHYV0s9ikFXfhZT27k=
Bytes: 1999
Keith Thompson writes:
> 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". [...]
Other people have different opinions on that question.