Re: A question on string literals



pete wrote:

> Richard Heathfield wrote:
>>
>> Chris Barts wrote:
>>
>> > In article <1123579479.194294.182390@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
>> > Sriram Rajagopalan wrote:
>> >>
>> >> char arr1[] = { "Hello" };
>> >> arr1 = 0; // Not allowed.
>>
>> Correct.
>>
>> >
>> > No, that is still allowed: The array 'decomposes' into a pointer
>>
>> Incorrect. Such decay happens only in value contexts,
>> and this is not such a context.
>
> I think it does happen. The standard describes the conversion
> as something that happens except in three cases.

It's a constraint violation: "an assignment operator shall have a modifiable
lvalue as its left operand". Therefore, a diagnostic message is required,
and the program is considered incorrect. The Standard does not define how
incorrect programs are translated, or how they behave.

>> arr1 = NULL; /* wrong */
>>
>> would still be an error.
>
> What kind of an error?

A constraint violation.

> The name of an array, if not converted,
> fits the K&R and the standards' descriptions of lvalue.
>
> Regarding
> arr1 = NULL;
> my compiler says: error C2106: '=' : left operand must be l-value

This is in accordance with the Standard, which requires a diagnostic for
that code.


--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain
.



Relevant Pages

  • Re: key block
    ... Richard Heathfield wrote: ... You'd be incorrect. ... I suspect Flash is correct. ... So it was created before the standard? ...
    (comp.lang.c)
  • Re: constructor
    ... I am curious where in the Standard there is evidence to your ... There is no apparent meaning in what you write here, ... That is incorrect. ... > lead to it), we get "I call another constructor from within my first, why ...
    (comp.lang.cpp)
  • Re: threads vs. processes
    ... >> stipulation you're making in the standard. ... > Your reading is incorrect because it is incorrect for real systems. ...
    (comp.unix.programmer)
  • Re: help w/ c/c++ problem
    ... Standard REQUIRES main to return an int. ... Then it is still incorrect. ... The function called at program startup is named main. ...
    (comp.lang.c)
  • Re: On-topicness
    ... except perhaps "The C Standard doesn't require your implementation to ... Nor does an otherwise correct answer suddenly become incorrect just ... so you had no info to assume he was making incorrect ... Navia had claimed that the OP was correct to think that "it is stack", ...
    (comp.lang.c)