Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #388108

Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?

From Tim Rentsch <tr.17687@z991.linuxsc.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 2024-09-03 06:11 -0700
Organization A noiseless patient Spider
Message-ID <861q20q3tz.fsf@linuxsc.com> (permalink)
References (4 earlier) <87zfpvfdk4.fsf@nosuchdomain.example.com> <v8ii17$2q5p1$1@dont-email.me> <87v80ig4vt.fsf@nosuchdomain.example.com> <86plqd2zhf.fsf@linuxsc.com> <87wmklh0dn.fsf@nosuchdomain.example.com>

Show all headers | View raw


Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

> Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
>
>> Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:
>>
>>> 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".  [...]
>>
>> Other people have different opinions on that question.
>
> You could have told us your opinion.  You could have explained why
> someone might have a different opinion.  You could have given us a
> good reason not to use "const", assuming there is such a reason.
> You know the language well enough to make me suspect you might
> have something specific in mind.  [...]

I said all that I thought needed saying.  I see no reason
to add to it.

Back to comp.lang.c | Previous | Next | Find similar


Thread

Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault? Tim Rentsch <tr.17687@z991.linuxsc.com> - 2024-09-03 06:11 -0700

csiph-web