Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #120467
| Path | csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| 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 | <lnwp4iwvdl.fsf@kst-u.example.com> (permalink) |
| References | <150a364a-68b1-4c35-9d34-e94bbf115d23@googlegroups.com> <lnefqqyfdx.fsf@kst-u.example.com> <ba150c26-406d-494f-993e-898d43feda63@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 |
Show key headers only | View raw
Thiago Adams <thiago.adams@gmail.com> 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 <http://www.ghoti.net/~kst>
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"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
literal string type Thiago Adams <thiago.adams@gmail.com> - 2017-09-28 07:41 -0700
Re: literal string type Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2017-09-28 07:50 -0700
Re: literal string type Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-09-28 19:12 +0100
Re: literal string type Keith Thompson <kst-u@mib.org> - 2017-09-28 09:08 -0700
Re: literal string type Thiago Adams <thiago.adams@gmail.com> - 2017-09-28 10:19 -0700
Re: literal string type Keith Thompson <kst-u@mib.org> - 2017-09-28 11:06 -0700
Re: literal string type Thiago Adams <thiago.adams@gmail.com> - 2017-09-28 11:41 -0700
csiph-web