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


Groups > comp.lang.c > #120467

Re: literal string type

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: literal string type
Date 2017-09-28 11:06 -0700
Organization None to speak of
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>

Show all headers | 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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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