This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: string is const char [] ?


Joe Buck <jbuck@Synopsys.COM> writes:

> On 23 Jun 1998, Alexandre Oliva wrote:
>> >> >   char a1[] = "test not const";

> I don't believe that you are correct, Alexandre.

Thank you all for pointing out my mistake.  When I was looking for the
requirement in the FDIS that stated that strings are char const[], I
came across the following statement, that surprised me:

  Example:
  char array[4] = "abcd";         // valid C, invalid C++

which I took in a more general sense than it should have been taken,
because I didn't read the text just before it [diff.decl]:

4 Change: In C++, when initializing an array of character with a string,
  the  number  of  characters  in  the string (including the terminating
  '\0') must not exceed the number of elements in the array. [...]


What I was really looking for was [diff.lex]:

4 Change: String literals made const
  The type of a string literal is changed from "array of char" to "array
  of const char."  The type of a wide string  literal  is  changed  from
  "array of wchar_t" to "array of const wchar_t."
[...]
  char* p = "abc";                // valid in C, deprecated in C++
  char* q = expr ? "abc" : "de";  // valid in C, invalid in C++

[conv.array]:

2 A string literal (_lex.string_) that is not a wide string literal  can
  be  converted  to  an  rvalue of type "pointer to char"; [...]
  Note:  this  conversion  is  deprecated.


Sorry for spreading misinformation.

-- 
Alexandre Oliva
mailto:oliva@dcc.unicamp.br mailto:aoliva@acm.org
http://www.dcc.unicamp.br/~oliva
Universidade Estadual de Campinas, SP, Brasil



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]