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


Groups > comp.lang.c > #55507

Re: string literals vs char*

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: string literals vs char*
Date 2014-12-27 12:08 -0800
Organization None to speak of
Message-ID <ln7fxczwij.fsf@nuthaus.mib.org> (permalink)
References <549e45b4$0$280$14726298@news.sunsite.dk> <m7mn61$pti$1@dont-email.me> <string-literals-20141227175008@ram.dialup.fu-berlin.de>

Show all headers | View raw


ram@zedat.fu-berlin.de (Stefan Ram) writes:
> James Kuyper <jameskuyper@verizon.net> writes:
>>String literals have the type char[n], where n is 1 more than the number
>
>   »N1570 6.4.5 String literals« does say that »The multibyte
>   character sequence is then used to initialize an array of
>   static storage duration and length just sufficient to
>   contain the sequence«, but it does not name the type as
>   »char[n]«. While you are probably right, I cannot find
>   this type explicitly given in N1570. (Surely, it says that
>   (char []){"/tmp/fileXXXXXX"} has this type.) I am not sure
>   whether it even says that the /value/ of a string literal
>   is this array. Maybe this is taken for granted?
>
>   I wish, however, that a formal specification would contain
>   wordings of the kind of: »The value of a string literal is
>   ...« and »The type of a string literal is ...«, and that
>   these wordings would bein the section titled »String
>   literals«. To achieve this, the best way is for every type
>   of expression and function to always explicitly give: value,
>   type, and effect - even if »none« or »unspecified«. (The new
>   C++ specifications get this a little bit better, because for
>   every function there is a separate section labeled »effect«
>   [if it has an effect].)
[...]

6.5.1 "Primary expressions" paragraph 4 says:

    A string literal is a primary expression. It is an lvalue with
    type as detailed in 6.4.5.

6.4.5p6 says:

    ... The multibyte character sequence is then used to initialize
    an array of static storage duration and length just sufficient
    to contain the sequence.  For character string literals, the
    array elements have type char, and are initialized with the
    individual bytes of the multibyte character sequence.

which I think is sufficient to specify that the string literal
"hello" is an lvalue of type char[6].

But I still don't see an explicit statement that the object
designated by the lvalue is actually the array object described
in 6.5.4.  That's the only sane interpretation, but unless I'm
missing something (which is a very real possibility) it's not
explicitly stated.

-- 
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


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