Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: literal string type Date: Thu, 28 Sep 2017 11:06:30 -0700 Organization: None to speak of Lines: 24 Message-ID: References: <150a364a-68b1-4c35-9d34-e94bbf115d23@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: reader02.eternal-september.org; posting-host="f02d66d70d400004528cf8384483c39b"; logging-data="23860"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Xo3mil2UPlG+waW/6GBy4" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:2yjvqdICtkukgeD0QkY3O0zTsNY= sha1:GTiirLZbBP9W5rc2Kcb00CsJaBo= Xref: csiph.com comp.lang.c:120467 Thiago Adams writes: > On Thursday, September 28, 2017 at 1:09:06 PM UTC-3, Keith Thompson wrote: > ... >> The string literal "a" is of type `char [2]`, which is implicitly >> converted to `char*`. Logically it would be better for it to be of type >> `const char[2]`, which would be converted to `const char*`, but it >> remains non-const for compatility with pre-ANSI C code (when "const" >> didn't exist). (C++ did make this change; a C++ compiler would >> diagnose, and perhaps reject, the above code.) > > In my option, it's a good warning to have, and a good point for > deprecation in the future. gcc's "-Wwrite-strings" option makes string literals const (which makes gcc non-conforming). Other compilers may have similar options. (Sometimes compiling with a C++ compiler can detect some errors that C compilers don't -- but of course not all valid C code is valid C++ code.) -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"