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


Groups > comp.lang.c > #55482

Re: string literals vs char*

From Ian Collins <ian-news@hotmail.com>
Newsgroups comp.lang.c
Subject Re: string literals vs char*
Date 2014-12-27 22:03 +1300
Message-ID <cg7avjF6itsU1@mid.individual.net> (permalink)
References <549e45b4$0$280$14726298@news.sunsite.dk> <ptss9a9fsoeqb304o4vmhht9qffb2414dg@4ax.com>

Show all headers | View raw


Barry Schwarz wrote:
> On 27 Dec 2014 05:37:56 GMT, arnuld <sunrise@invalid.address> wrote:
>
>> C90 requires that string literls are constant, then why I am not getting
>> warning here. Is this a compiler problem ?  (if it is a compiler problem
>
> There is a difference between constant and const.  String literals
> have always been considered constant (modifying one causes undefined
> behavior).  However, for historical reasons (not breaking really old
> code) they are not const.  Hence no diagnostic.  You are however free
> to define the pointer properly as
>       const char *p1;
> which would have no effect on the operation of your program.
>
>> then why g++ catches the error at compile time when gccdoes not):
>
> I don't use g++ but based on the text of the diagnostic, it appears
> that g++ treats the literals as const due to the specified option
> being in effect.  If you compiled the program without that option, I
> would expect the diagnostic to disappear.

No, they would remain.  g++ is a C++ compiler and C++ fixes C's const 
omissions.

-- 
Ian Collins

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

string literals vs char* arnuld <sunrise@invalid.address> - 2014-12-27 05:37 +0000
  Re: string literals vs char* Kaz Kylheku <kaz@kylheku.com> - 2014-12-27 06:36 +0000
  Re: string literals vs char* Barry Schwarz <schwarzb@dqel.com> - 2014-12-27 00:58 -0800
    Re: string literals vs char* Ian Collins <ian-news@hotmail.com> - 2014-12-27 22:03 +1300
    Re: string literals vs char* Keith Thompson <kst-u@mib.org> - 2014-12-27 11:55 -0800
      Re: string literals vs char* glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-12-28 07:55 +0000
        Re: string literals vs char* Ben Bacarisse <ben.usenet@bsb.me.uk> - 2014-12-28 11:39 +0000
          Re: string literals vs char* Tim Rentsch <txr@alumni.caltech.edu> - 2015-03-24 08:55 -0700
            Re: string literals vs char* Keith Thompson <kst-u@mib.org> - 2015-03-24 12:17 -0700
  Re: string literals vs char* James Kuyper <jameskuyper@verizon.net> - 2014-12-27 11:36 -0500
    Re: string literals vs char* Vincenzo Mercuri <nomail@yahoo.it> - 2014-12-27 18:20 +0100
      Re: string literals vs char* Vincenzo Mercuri <nomail@yahoo.it> - 2014-12-27 18:55 +0100
    Re: string literals vs char* Kaz Kylheku <kaz@kylheku.com> - 2014-12-27 17:25 +0000
    Re: string literals vs char* Keith Thompson <kst-u@mib.org> - 2014-12-27 12:08 -0800
    Re: string literals vs char* James Kuyper <jameskuyper@verizon.net> - 2014-12-28 07:01 -0500
  Re: string literals vs char* John Bode <jfbode1029@gmail.com> - 2014-12-30 10:52 -0800

csiph-web