Re: A question on string literals
- From: Richard Heathfield <invalid@xxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 13 Aug 2005 10:07:22 +0000 (UTC)
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
.
- Follow-Ups:
- Re: A question on string literals
- From: pete
- Re: A question on string literals
- References:
- A question on string literals
- From: junky_fellow
- Re: A question on string literals
- From: Sriram Rajagopalan
- Re: A question on string literals
- From: Chris Barts
- Re: A question on string literals
- From: Richard Heathfield
- Re: A question on string literals
- From: pete
- A question on string literals
- Prev by Date: Re: A question on string literals
- Next by Date: Re: How to get the total row number of a text file
- Previous by thread: Re: A question on string literals
- Next by thread: Re: A question on string literals
- Index(es):
Relevant Pages
|