Sujet : Re: No warning at implicit removal of const. Was: relearning C: why does an in-place change to a char* segfault?
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.cDate : 12. Aug 2024, 22:55:32
Autres entêtes
Organisation : None to speak of
Message-ID : <87wmklh0dn.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13)
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.
That could have been interesting and useful.
Instead, you chose to waste everyone's time with a practically
content-free response.
Yes, different people have different opinions. Golly, I never
knew that.
-- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.comvoid Void(void) { Void(); } /* The recursive call of the void */