Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

In specifications, Murphy's Law supersedes Ohm's.


devel / comp.lang.c / Re: Array is an non-modifiable lvalue - where does it matter?

SubjectAuthor
* Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
+* Re: Array is an non-modifiable lvalue - where does it matter?Öö Tiib
|+* Re: Array is an non-modifiable lvalue - where does it matter?Ben Bacarisse
||`* Re: Array is an non-modifiable lvalue - where does it matter?Öö Tiib
|| `* Re: Array is an non-modifiable lvalue - where does it matter?David Brown
||  +- Re: Array is an non-modifiable lvalue - where does it matter?Keith Thompson
||  `* Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
||   `* Re: Array is an non-modifiable lvalue - where does it matter?David Brown
||    `- Re: Array is an non-modifiable lvalue - where does it matter?James Kuyper
|`* Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
| `- Re: Array is an non-modifiable lvalue - where does it matter?Öö Tiib
+- Re: Array is an non-modifiable lvalue - where does it matter?Keith Thompson
+* Re: Array is an non-modifiable lvalue - where does it matter?James Kuyper
|+* Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
||`* Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
|| +- Re: Array is an non-modifiable lvalue - where does it matter?Keith Thompson
|| `- Re: Array is an non-modifiable lvalue - where does it matter?Siri Cruise
|`- Re: Array is an non-modifiable lvalue - where does it matter?Keith Thompson
+* Re: Array is an non-modifiable lvalue - where does it matter?Kaz Kylheku
|+* Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
||+* Re: Array is an non-modifiable lvalue - where does it matter?Kaz Kylheku
|||+- Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
|||`- Re: Array is an non-modifiable lvalue - where does it matter?Keith Thompson
||`- Re: Array is an non-modifiable lvalue - where does it matter?Ben Bacarisse
|`- Re: Array is an non-modifiable lvalue - where does it matter?James Kuyper
`* Re: Array is an non-modifiable lvalue - where does it matter?Chris M. Thomasson
 `* Re: Array is an non-modifiable lvalue - where does it matter?Andrey Tarasevich
  `- Re: Array is an non-modifiable lvalue - where does it matter?Chris M. Thomasson

Pages:12
Array is an non-modifiable lvalue - where does it matter?

<scq5c5$tql$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17502&group=comp.lang.c#17502

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Array is an non-modifiable lvalue - where does it matter?
Date: Thu, 15 Jul 2021 13:21:22 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <scq5c5$tql$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 15 Jul 2021 20:21:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a9d80eafc20ce019efd617021499f254";
logging-data="30549"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IgLZp369U2Wj/Kve/wrLt"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:dcVn9rfaGmsCL7kLrZzAmBKm49c=
Content-Language: en-US
X-Mozilla-News-Host: news://news.eternal-september.org:119
 by: Andrey Tarasevich - Thu, 15 Jul 2021 20:21 UTC

6.3.2/1 says that

1 [...] A modifiable lvalue is an lvalue that does not have array
type, [...]

Based on that, arrays are non-modifiable lvalues. We all know what it
actually means. But is there any context in the standard in which this
non-modifiability of array lvalues would actually _matter_, would
actually interact with some other standard requirement?

One thing that comes to mind is a constraint on assignment operators
(6.5.16/2)

2 An assignment operator shall have a modifiable lvalue as its left
operand.

So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
assign to arrays. But I believe that constraints are intended/supposed
to be applied after automatic implicit conversions. And since LHS of
assignment is not one of the contexts excluded from array type decay,
said decay is already sufficient to prevent assignment to arrays.

Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
before automatic implicit conversions or after them?

And if the answer is "after", then is there any other context in C
standard where non-modifiability of array lvalues would make a difference?

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17503&group=comp.lang.c#17503

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:1195:: with SMTP id b21mr5698736qkk.71.1626382532277; Thu, 15 Jul 2021 13:55:32 -0700 (PDT)
X-Received: by 2002:ae9:e911:: with SMTP id x17mr5880030qkf.371.1626382532118; Thu, 15 Jul 2021 13:55:32 -0700 (PDT)
Path: i2pn2.org!i2pn.org!news.uzoreto.com!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr3.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 15 Jul 2021 13:55:31 -0700 (PDT)
In-Reply-To: <scq5c5$tql$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=145.14.19.135; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 145.14.19.135
References: <scq5c5$tql$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Thu, 15 Jul 2021 20:55:32 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 32
 by: Öö Tiib - Thu, 15 Jul 2021 20:55 UTC

On Thursday, 15 July 2021 at 23:21:37 UTC+3, Andrey Tarasevich wrote:
> 6.3.2/1 says that
>
> 1 [...] A modifiable lvalue is an lvalue that does not have array
> type, [...]
>
> Based on that, arrays are non-modifiable lvalues. We all know what it
> actually means. But is there any context in the standard in which this
> non-modifiability of array lvalues would actually _matter_, would
> actually interact with some other standard requirement?
>
> One thing that comes to mind is a constraint on assignment operators
> (6.5.16/2)
>
> 2 An assignment operator shall have a modifiable lvalue as its left
> operand.
>
> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
> assign to arrays. But I believe that constraints are intended/supposed
> to be applied after automatic implicit conversions. And since LHS of
> assignment is not one of the contexts excluded from array type decay,
> said decay is already sufficient to prevent assignment to arrays.
>
> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
> before automatic implicit conversions or after them?
>
> And if the answer is "after", then is there any other context in C
> standard where non-modifiability of array lvalues would make a difference?

It is so that we can't modify address of array so
rest of operators that can modify lvalue like ++ or += also
will be rejected on case of an array. But I might misunderstand
what you are asking.

Re: Array is an non-modifiable lvalue - where does it matter?

<87im1b2snz.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17504&group=comp.lang.c#17504

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Thu, 15 Jul 2021 14:06:40 -0700
Organization: None to speak of
Lines: 50
Message-ID: <87im1b2snz.fsf@nosuchdomain.example.com>
References: <scq5c5$tql$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="ea9f25db98250ad3c2095bb4c90a3161";
logging-data="11401"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UFFySqsfOhb5xPftIk7/X"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:RPGlun8TnrC+5TfbFBNzmUL3qS0=
sha1:PHS7bfoGHYx8aWAqGAQ3DoYromk=
 by: Keith Thompson - Thu, 15 Jul 2021 21:06 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
> 6.3.2/1 says that
>
> 1 [...] A modifiable lvalue is an lvalue that does not have array
> type, [...]
>
> Based on that, arrays are non-modifiable lvalues. We all know what it
> actually means. But is there any context in the standard in which this
> non-modifiability of array lvalues would actually _matter_, would
> actually interact with some other standard requirement?
>
> One thing that comes to mind is a constraint on assignment operators
> (6.5.16/2)
>
> 2 An assignment operator shall have a modifiable lvalue as its left
> operand.
>
> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
> assign to arrays. But I believe that constraints are intended/supposed
> to be applied after automatic implicit conversions. And since LHS of
> assignment is not one of the contexts excluded from array type decay,
> said decay is already sufficient to prevent assignment to arrays.
>
> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
> before automatic implicit conversions or after them?
>
> And if the answer is "after", then is there any other context in C
> standard where non-modifiability of array lvalues would make a
> difference?

My first thought is that the statement is redundant (and that's not
necessarily a bad thing). Other requirements imply that you can't
assign to arrays, but it doesn't hurt to have an explicit statement to
that effect.

The full definition is:

A *modifiable lvalue* is an lvalue that does not have array
type, does not have an incomplete type, does not have a const-
qualified type, and if it is a structure or union, does not have
any member (including, recursively, any member or element of
all contained aggregates or unions) with a const- qualified type.

I *think* that dropping the "does not have array type" wouldn't change
anything, but it's probably clearer as it is.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Array is an non-modifiable lvalue - where does it matter?

<875yxbth6r.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17505&group=comp.lang.c#17505

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Thu, 15 Jul 2021 22:12:28 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <875yxbth6r.fsf@bsb.me.uk>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="bb748f6c5215520c5ad6c1131197b0a0";
logging-data="12788"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19C7ZTPGCXfXAXW6U9d+64Em9t+t3AbrBA="
Cancel-Lock: sha1:ZoGHYcfYw0vPBVRysK9scccsE00=
sha1:Vo5LhaXUMosFzF/KFrU6CISyPQs=
X-BSB-Auth: 1.6cf955f5f4189a4b27fe.20210715221228BST.875yxbth6r.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 15 Jul 2021 21:12 UTC

Öö Tiib <ootiib@hot.ee> writes:

> On Thursday, 15 July 2021 at 23:21:37 UTC+3, Andrey Tarasevich wrote:
>> 6.3.2/1 says that
>>
>> 1 [...] A modifiable lvalue is an lvalue that does not have array
>> type, [...]
>>
>> Based on that, arrays are non-modifiable lvalues. We all know what it
>> actually means. But is there any context in the standard in which this
>> non-modifiability of array lvalues would actually _matter_, would
>> actually interact with some other standard requirement?
>>
>> One thing that comes to mind is a constraint on assignment operators
>> (6.5.16/2)
>>
>> 2 An assignment operator shall have a modifiable lvalue as its left
>> operand.
>>
>> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
>> assign to arrays. But I believe that constraints are intended/supposed
>> to be applied after automatic implicit conversions. And since LHS of
>> assignment is not one of the contexts excluded from array type decay,
>> said decay is already sufficient to prevent assignment to arrays.
>>
>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>> before automatic implicit conversions or after them?
>>
>> And if the answer is "after", then is there any other context in C
>> standard where non-modifiability of array lvalues would make a difference?
>
> It is so that we can't modify address of array so
> rest of operators that can modify lvalue like ++ or += also
> will be rejected on case of an array. But I might misunderstand
> what you are asking.

Yes, you've missed the point of the question. Lvalue expressions of
array type are, in almost all situations, converted to pointers to the
first element of the array, and *the result is no longer an lvalue*.
(The exceptions are the operands of &, sizeof and _Alignof and when a
string literal is used to initialise an array.)

Thus, given `int a[1]`, the expression `a++` is invalid because the
operand is not an lvalue at all.

Andrey is asking whether there are any situations where it matters that
the standard excludes array-valued lvalues from being modifiable
lvalues. Could that wording simply have been left out or would that
permit something, not excluded by other wording, from being valid C?

I *think* the answer is yes -- there would be no harm (other than maybe
a loss of clarity) in removing that wording. But I had deliberately not
answered because this is the sort of question that requires a more
thorough knowledge of the standard than I possess to answer with any
confidence.

--
Ben.

Re: Array is an non-modifiable lvalue - where does it matter?

<scq9pd$j11$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17506&group=comp.lang.c#17506

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Thu, 15 Jul 2021 14:36:45 -0700
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <scq9pd$j11$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 15 Jul 2021 21:36:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a9d80eafc20ce019efd617021499f254";
logging-data="19489"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+vGiOPrIc/4pKpErmTa5aK"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:cnPdN6HZvcaB9UtSzjObAvtlKes=
In-Reply-To: <5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
Content-Language: en-US
 by: Andrey Tarasevich - Thu, 15 Jul 2021 21:36 UTC

On 7/15/2021 1:55 PM, Öö Tiib wrote:
>
> It is so that we can't modify address of array so
> rest of operators that can modify lvalue like ++ or += also
> will be rejected on case of an array. But I might misunderstand
> what you are asking.

Um... I don't see what you are trying to say here. There's no such
concept in C as "modifying an address of an exiting object". No need to
block or prevent it, for arrays or for anything else.

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17507&group=comp.lang.c#17507

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a37:71c1:: with SMTP id m184mr6458059qkc.367.1626386854162; Thu, 15 Jul 2021 15:07:34 -0700 (PDT)
X-Received: by 2002:ac8:4e4d:: with SMTP id e13mr6199275qtw.380.1626386854034; Thu, 15 Jul 2021 15:07:34 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!tr1.eu1.usenetexpress.com!feeder.usenetexpress.com!tr2.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 15 Jul 2021 15:07:33 -0700 (PDT)
In-Reply-To: <875yxbth6r.fsf@bsb.me.uk>
Injection-Info: google-groups.googlegroups.com; posting-host=145.14.19.135; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 145.14.19.135
References: <scq5c5$tql$1@dont-email.me> <5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com> <875yxbth6r.fsf@bsb.me.uk>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Thu, 15 Jul 2021 22:07:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 76
 by: Öö Tiib - Thu, 15 Jul 2021 22:07 UTC

On Friday, 16 July 2021 at 00:12:40 UTC+3, Ben Bacarisse wrote:
> Öö Tiib <oot...@hot.ee> writes:
>
> > On Thursday, 15 July 2021 at 23:21:37 UTC+3, Andrey Tarasevich wrote:
> >> 6.3.2/1 says that
> >>
> >> 1 [...] A modifiable lvalue is an lvalue that does not have array
> >> type, [...]
> >>
> >> Based on that, arrays are non-modifiable lvalues. We all know what it
> >> actually means. But is there any context in the standard in which this
> >> non-modifiability of array lvalues would actually _matter_, would
> >> actually interact with some other standard requirement?
> >>
> >> One thing that comes to mind is a constraint on assignment operators
> >> (6.5.16/2)
> >>
> >> 2 An assignment operator shall have a modifiable lvalue as its left
> >> operand.
> >>
> >> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
> >> assign to arrays. But I believe that constraints are intended/supposed
> >> to be applied after automatic implicit conversions. And since LHS of
> >> assignment is not one of the contexts excluded from array type decay,
> >> said decay is already sufficient to prevent assignment to arrays.
> >>
> >> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
> >> before automatic implicit conversions or after them?
> >>
> >> And if the answer is "after", then is there any other context in C
> >> standard where non-modifiability of array lvalues would make a difference?
> >
> > It is so that we can't modify address of array so
> > rest of operators that can modify lvalue like ++ or += also
> > will be rejected on case of an array. But I might misunderstand
> > what you are asking.
>
> Yes, you've missed the point of the question. Lvalue expressions of
> array type are, in almost all situations, converted to pointers to the
> first element of the array, and *the result is no longer an lvalue*.
> (The exceptions are the operands of &, sizeof and _Alignof and when a
> string literal is used to initialise an array.)
>
> Thus, given `int a[1]`, the expression `a++` is invalid because the
> operand is not an lvalue at all.

Yes and so a = b is invalid because a turns into something that is
not lvalue at all. But saying that it is not modifiable does not hurt?
> Andrey is asking whether there are any situations where it matters that
> the standard excludes array-valued lvalues from being modifiable
> lvalues. Could that wording simply have been left out or would that
> permit something, not excluded by other wording, from being valid C?
>
> I *think* the answer is yes -- there would be no harm (other than maybe
> a loss of clarity) in removing that wording. But I had deliberately not
> answered because this is the sort of question that requires a more
> thorough knowledge of the standard than I possess to answer with any
> confidence.

Thanks for clarifying. I don't think that it is bad when standard repeats
something over even if it is deducible from other parts. Especially
about arrays that seem to be constant source of confusion among
people who try to learn C.

Re: Array is an non-modifiable lvalue - where does it matter?

<bd014848-757b-4a01-80d4-a3be029ff20fn@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17508&group=comp.lang.c#17508

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:90c:: with SMTP id v12mr6359967qkv.190.1626387576069;
Thu, 15 Jul 2021 15:19:36 -0700 (PDT)
X-Received: by 2002:a05:6214:178d:: with SMTP id ct13mr6906087qvb.22.1626387575915;
Thu, 15 Jul 2021 15:19:35 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 15 Jul 2021 15:19:35 -0700 (PDT)
In-Reply-To: <scq9pd$j11$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=145.14.19.135; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 145.14.19.135
References: <scq5c5$tql$1@dont-email.me> <5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
<scq9pd$j11$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <bd014848-757b-4a01-80d4-a3be029ff20fn@googlegroups.com>
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Thu, 15 Jul 2021 22:19:36 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: Öö Tiib - Thu, 15 Jul 2021 22:19 UTC

On Friday, 16 July 2021 at 00:36:57 UTC+3, Andrey Tarasevich wrote:
> On 7/15/2021 1:55 PM, Öö Tiib wrote:
> >
> > It is so that we can't modify address of array so
> > rest of operators that can modify lvalue like ++ or += also
> > will be rejected on case of an array. But I might misunderstand
> > what you are asking.
> Um... I don't see what you are trying to say here. There's no such
> concept in C as "modifying an address of an exiting object". No need to
> block or prevent it, for arrays or for anything else.

Yes, but that does not matter that there are no features or concepts
in C. After figuring that array decays to pointer a novice tries to
modify that pointer sooner or later. Sometimes "successfully" as array
"parameter" is actually a pointer. Being maximally brief about that
unlucky and confusing feature is bad idea.

Re: Array is an non-modifiable lvalue - where does it matter?

<scrdrf$g4r$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17509&group=comp.lang.c#17509

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 09:52:14 +0200
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <scrdrf$g4r$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
<875yxbth6r.fsf@bsb.me.uk>
<e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 16 Jul 2021 07:52:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="14fad44d9931c818dc7a0bfa7583361b";
logging-data="16539"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/2a9LqR+CxtRh+h+cYyF3SMd+feTZJIkU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:U+OP6gzKKSm7f101hmPiEwYeAwY=
In-Reply-To: <e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Fri, 16 Jul 2021 07:52 UTC

On 16/07/2021 00:07, Öö Tiib wrote:
> On Friday, 16 July 2021 at 00:12:40 UTC+3, Ben Bacarisse wrote:
>> Öö Tiib <oot...@hot.ee> writes:
>>
>>> On Thursday, 15 July 2021 at 23:21:37 UTC+3, Andrey Tarasevich wrote:
>>>> 6.3.2/1 says that
>>>>
>>>> 1 [...] A modifiable lvalue is an lvalue that does not have array
>>>> type, [...]
>>>>
>>>> Based on that, arrays are non-modifiable lvalues. We all know what it
>>>> actually means. But is there any context in the standard in which this
>>>> non-modifiability of array lvalues would actually _matter_, would
>>>> actually interact with some other standard requirement?
>>>>
>>>> One thing that comes to mind is a constraint on assignment operators
>>>> (6.5.16/2)
>>>>
>>>> 2 An assignment operator shall have a modifiable lvalue as its left
>>>> operand.
>>>>
>>>> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
>>>> assign to arrays. But I believe that constraints are intended/supposed
>>>> to be applied after automatic implicit conversions. And since LHS of
>>>> assignment is not one of the contexts excluded from array type decay,
>>>> said decay is already sufficient to prevent assignment to arrays.
>>>>
>>>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>>>> before automatic implicit conversions or after them?
>>>>
>>>> And if the answer is "after", then is there any other context in C
>>>> standard where non-modifiability of array lvalues would make a difference?
>>>
>>> It is so that we can't modify address of array so
>>> rest of operators that can modify lvalue like ++ or += also
>>> will be rejected on case of an array. But I might misunderstand
>>> what you are asking.
>>
>> Yes, you've missed the point of the question. Lvalue expressions of
>> array type are, in almost all situations, converted to pointers to the
>> first element of the array, and *the result is no longer an lvalue*.
>> (The exceptions are the operands of &, sizeof and _Alignof and when a
>> string literal is used to initialise an array.)
>>
>> Thus, given `int a[1]`, the expression `a++` is invalid because the
>> operand is not an lvalue at all.
>
> Yes and so a = b is invalid because a turns into something that is
> not lvalue at all. But saying that it is not modifiable does not hurt?
>

As far as I can tell (there are others here that are better than I at
interpreting the exact wording of the standards), the wording in the
standard has been misinterpreted here.

The standard says "A modifiable lvalue is an lvalue that does not have
array type". When applied to "a = b", this has been interpreted to mean
that "a" is an lvalue of array type and therefore a non-modifiable
lvalue, so you cannot use the assignment. This is, AFAICS, subtly
incorrect - used here, "a" is converted to a non-lvalue pointer to its
first element. It is not an lvalue at all, modifiable or non-modifiable.

Re: Array is an non-modifiable lvalue - where does it matter?

<87eeby38rd.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17511&group=comp.lang.c#17511

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 02:31:18 -0700
Organization: None to speak of
Lines: 83
Message-ID: <87eeby38rd.fsf@nosuchdomain.example.com>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
<875yxbth6r.fsf@bsb.me.uk>
<e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
<scrdrf$g4r$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="25c9c1bea30ea2af62c752c5e5bf9013";
logging-data="16442"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tYGEGRmwgNwkhRL1fwNab"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:rKTmpBbTvQeb+abS71CLsMafDGQ=
sha1:Vc/3EAxV40CJ1Sue1NjDcWTCWpM=
 by: Keith Thompson - Fri, 16 Jul 2021 09:31 UTC

David Brown <david.brown@hesbynett.no> writes:
> On 16/07/2021 00:07, Öö Tiib wrote:
>> On Friday, 16 July 2021 at 00:12:40 UTC+3, Ben Bacarisse wrote:
>>> Öö Tiib <oot...@hot.ee> writes:
>>>
>>>> On Thursday, 15 July 2021 at 23:21:37 UTC+3, Andrey Tarasevich wrote:
>>>>> 6.3.2/1 says that
>>>>>
>>>>> 1 [...] A modifiable lvalue is an lvalue that does not have array
>>>>> type, [...]
>>>>>
>>>>> Based on that, arrays are non-modifiable lvalues. We all know what it
>>>>> actually means. But is there any context in the standard in which this
>>>>> non-modifiability of array lvalues would actually _matter_, would
>>>>> actually interact with some other standard requirement?
>>>>>
>>>>> One thing that comes to mind is a constraint on assignment operators
>>>>> (6.5.16/2)
>>>>>
>>>>> 2 An assignment operator shall have a modifiable lvalue as its left
>>>>> operand.
>>>>>
>>>>> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
>>>>> assign to arrays. But I believe that constraints are intended/supposed
>>>>> to be applied after automatic implicit conversions. And since LHS of
>>>>> assignment is not one of the contexts excluded from array type decay,
>>>>> said decay is already sufficient to prevent assignment to arrays.
>>>>>
>>>>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>>>>> before automatic implicit conversions or after them?
>>>>>
>>>>> And if the answer is "after", then is there any other context in C
>>>>> standard where non-modifiability of array lvalues would make a difference?
>>>>
>>>> It is so that we can't modify address of array so
>>>> rest of operators that can modify lvalue like ++ or += also
>>>> will be rejected on case of an array. But I might misunderstand
>>>> what you are asking.
>>>
>>> Yes, you've missed the point of the question. Lvalue expressions of
>>> array type are, in almost all situations, converted to pointers to the
>>> first element of the array, and *the result is no longer an lvalue*.
>>> (The exceptions are the operands of &, sizeof and _Alignof and when a
>>> string literal is used to initialise an array.)
>>>
>>> Thus, given `int a[1]`, the expression `a++` is invalid because the
>>> operand is not an lvalue at all.
>>
>> Yes and so a = b is invalid because a turns into something that is
>> not lvalue at all. But saying that it is not modifiable does not hurt?
>
> As far as I can tell (there are others here that are better than I at
> interpreting the exact wording of the standards), the wording in the
> standard has been misinterpreted here.
>
> The standard says "A modifiable lvalue is an lvalue that does not have
> array type". When applied to "a = b", this has been interpreted to mean
> that "a" is an lvalue of array type and therefore a non-modifiable
> lvalue, so you cannot use the assignment. This is, AFAICS, subtly
> incorrect - used here, "a" is converted to a non-lvalue pointer to its
> first element. It is not an lvalue at all, modifiable or non-modifiable.

I think that both of the previous posters in this thread, Ben and Öö,
have correctly said essentially the same think you're saying, that `a`
(after the array-to-pointer conversion) is not an lvalue at all. I'm
not sure that anyone here has misinterpreted it in the way you suggest.

If you write

int arr[10];
size_t s = sizeof arr;

then the expression arr in the second line is an lvalue (because it
designates an object and there's no array-to-pointer conversion)
*and* is not a modifiable lvalue (because it's of array type).
If the "does not have array type" wording were dropped, then arr
would be a modifiable lvalue -- but there's no attempt to modify it,
so it doesn't matter.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Array is an non-modifiable lvalue - where does it matter?

<scshd7$r7p$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17521&group=comp.lang.c#17521

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 10:59:02 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <scshd7$r7p$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
<875yxbth6r.fsf@bsb.me.uk>
<e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
<scrdrf$g4r$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Jul 2021 17:59:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="456a0a73af54c4d655588bf744b9f815";
logging-data="27897"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PSErj/28sJ56v1F3GqX3Z"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:GxhHyWL/Lzp4tiEJHQcib5Ou290=
In-Reply-To: <scrdrf$g4r$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Fri, 16 Jul 2021 17:59 UTC

On 7/16/2021 12:52 AM, David Brown wrote:
>
> The standard says "A modifiable lvalue is an lvalue that does not have
> array type". When applied to "a = b", this has been interpreted to mean
> that "a" is an lvalue of array type and therefore a non-modifiable
> lvalue, so you cannot use the assignment. This is, AFAICS, subtly
> incorrect - used here, "a" is converted to a non-lvalue pointer to its
> first element. It is not an lvalue at all, modifiable or non-modifiable.
>

That's actually part of the question I was asking originally.

You are implicitly insisting that the array-to-pointer conversion should
be applied first, and only after that the constraints of the assignment
operator should be checked.

Can you provide a reference to C standard that would indicate that it is
supposed to be done in that specific order, and not the other way around?

For example, C++ standard is known to use wording like "this (conversion
| transformation | adjustment) is applied before and further (analysis |
consideration) is performed" in order to eliminate such ambiguities.

But I don't see anything like that in C standard. One can argue that it
doesn't matter since the outcome is functionally the same either way.
But still... the question is intended as a "language-lawyer" one.

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<scsiq3$ens$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17522&group=comp.lang.c#17522

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 14:22:59 -0400
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <scsiq3$ens$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Jul 2021 18:22:59 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="2c6205e04a16d2ee07dfe43e70d7d75f";
logging-data="15100"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18XHXGhILCSodcennLJsXEL2Mf/5wPwfgw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:+BFtt1gV1zUnXn95t5OM6nygLlg=
In-Reply-To: <scq5c5$tql$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Fri, 16 Jul 2021 18:22 UTC

On 7/15/21 4:21 PM, Andrey Tarasevich wrote:
> 6.3.2/1 says that
>
> 1 [...] A modifiable lvalue is an lvalue that does not have array
> type, [...]
>
> Based on that, arrays are non-modifiable lvalues. We all know what it
> actually means. But is there any context in the standard in which this
> non-modifiability of array lvalues would actually _matter_, would
> actually interact with some other standard requirement?
>
> One thing that comes to mind is a constraint on assignment operators
> (6.5.16/2)
>
> 2 An assignment operator shall have a modifiable lvalue as its left
> operand.
>
> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
> assign to arrays. But I believe that constraints are intended/supposed
> to be applied after automatic implicit conversions. And since LHS of
> assignment is not one of the contexts excluded from array type decay,
> said decay is already sufficient to prevent assignment to arrays.

The Rationale says "the fact that a[i] is a modifiable lvalue while a is
not has puzzled many students of the language. A more precise
description was incorporated in C89 in the hope of combatting this
confusion."

I have a vague memory that this wording is connected to a subtle issue
with functions that return values of struct type, where the struct
contains an array member. But I can't remember what the issue was.

Re: Array is an non-modifiable lvalue - where does it matter?

<scsk02$v8i$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17523&group=comp.lang.c#17523

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 11:43:13 -0700
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <scsk02$v8i$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me> <scsiq3$ens$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Jul 2021 18:43:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="456a0a73af54c4d655588bf744b9f815";
logging-data="32018"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qQmMFsIwqeHBM3irXuQle"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:V5XIcqYWKCpdPC2YGFNOfr+Zmzo=
In-Reply-To: <scsiq3$ens$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Fri, 16 Jul 2021 18:43 UTC

On 7/16/2021 11:22 AM, James Kuyper wrote:
>
> I have a vague memory that this wording is connected to a subtle issue
> with functions that return values of struct type, where the struct
> contains an array member. But I can't remember what the issue was.
>

The issue(s) stem from the combination of the following bits and pieces:

1. Function return is always an rvalue
2. Member array of an rvalue struct object is also an rvalue
3. The result of unary '*' is always an lvalue. And, say, `[]` is
defined through unary '*' and '+'.

2 and 3 conflict with each other.

C89/90 resolved this problem by stating that array-to-pointer conversion
is only applicable to lvalue arrays. This basically made rvalue arrays
inaccessible

struct S { int a[10]; };

struct S foo(void)
{
struct S s = { 0 };
return s;
}

int main()
{
int i = foo().a[0]; /* <- error in C89/90 */
return 0;
}

The above code would report a constraint violation: it is not possible
to apply `[]` to `foo().a`.

C99 decided to change that. Starting from C99 array-to-pointer
conversion is applicable to rvalue arrays as well, which legalized

int i = foo().a[0]; /* <- OK in C99 */

but created another issue

foo().a[0] = 42; /* are we assigning to an rvalue here? */

C99 cops out of this latter problem by stating that the behavior is
undefined in this case.

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<20210716145835.570@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17526&group=comp.lang.c#17526

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 22:21:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <20210716145835.570@kylheku.com>
References: <scq5c5$tql$1@dont-email.me>
Injection-Date: Fri, 16 Jul 2021 22:21:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4ef5227146a28e9915a37e47ddc34671";
logging-data="3504"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y+N/R8tNwE4hSuBOzmOhN7NmZ+Gsqnpc="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:nPj9cT5YHWa1r7KAyMKcJAySdPA=
 by: Kaz Kylheku - Fri, 16 Jul 2021 22:21 UTC

On 2021-07-15, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
> 6.3.2/1 says that
>
> 1 [...] A modifiable lvalue is an lvalue that does not have array
> type, [...]
>
> Based on that, arrays are non-modifiable lvalues. We all know what it
> actually means. But is there any context in the standard in which this
> non-modifiability of array lvalues would actually _matter_, would
> actually interact with some other standard requirement?

If what you are getting at is this: could a C dialect provide complete
support for array passing, returning and assignment, while conforming
to the current standard?

The answer is no.

A conforming extension of behavior could be to allow arrays to be
modifiable lvalues: emit the required diagnostic, and then allow
assignment or initialization; e.g.

int a[10] = { 0 };
int b[10] = a;
int c[10];
c = b;

FUrthermore, function declaration syntax for returning arrays could
be added without conflict:

int foo(void)[10];
c = foo();

Where we run aground is the fact that parameter declarations of
array type actually declare a pointer. This is the case even
if they specify a dimension:

void foo(int a[42]); // actually (int *a)

that kind of puts a monkey wrench into an otherwise reasonably
tidy plan to extend the language.

Passing arguments to parameters is very similar to assignment;
An assignable array proposal which doesn't permit passing would
introduce an ugly inconsistency.

> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
> assign to arrays. But I believe that constraints are intended/supposed
> to be applied after automatic implicit conversions. And since LHS of
> assignment is not one of the contexts excluded from array type decay,
> said decay is already sufficient to prevent assignment to arrays.

Indeed, an implementation can implement the constraint that arrays are not
modifiable lvalues simply by imposing the "decay rule" in all contexts
other than when the array is the operand of & (address-of) or sizeof.

The array is then not assignable by virtue of having been converted
to a pointer which is not an lvalue. If it's not an lvalue, it's not
a modifiable lvalue: requirement satisfied.

> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
> before automatic implicit conversions or after them?

It looks moot. Before conversion to pointer, you have an array lvalue,
and the requirement says that it' not modifiable. Thus, cannot assign to
it. After conversion to pointer, you don't have an lvalue. Not
assignable, either.

Which case it is basically is only germane to the wording of the
constraint violation diagnostic, and that is not specified.

A compiler which diagnoses the assignment as "cannot assign to a
calculated pointer" is conforming; it has produced the required
diagnostic.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Array is an non-modifiable lvalue - where does it matter?

<875yx93nnb.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17527&group=comp.lang.c#17527

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 15:22:00 -0700
Organization: None to speak of
Lines: 56
Message-ID: <875yx93nnb.fsf@nosuchdomain.example.com>
References: <scq5c5$tql$1@dont-email.me> <scsiq3$ens$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="54b9e5b9899999611d969dd6d5e30777";
logging-data="3992"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ghg2yAry1IlSnRDYYxi2i"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:ixDfsExaRfA1x4kKRcM2kNrsNvs=
sha1:7mmHTreylj0ZfoqymH3Gv3a/6CY=
 by: Keith Thompson - Fri, 16 Jul 2021 22:22 UTC

James Kuyper <jameskuyper@alumni.caltech.edu> writes:
> On 7/15/21 4:21 PM, Andrey Tarasevich wrote:
>> 6.3.2/1 says that
>>
>> 1 [...] A modifiable lvalue is an lvalue that does not have array
>> type, [...]
>>
>> Based on that, arrays are non-modifiable lvalues. We all know what it
>> actually means. But is there any context in the standard in which this
>> non-modifiability of array lvalues would actually _matter_, would
>> actually interact with some other standard requirement?
>>
>> One thing that comes to mind is a constraint on assignment operators
>> (6.5.16/2)
>>
>> 2 An assignment operator shall have a modifiable lvalue as its left
>> operand.
>>
>> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
>> assign to arrays. But I believe that constraints are intended/supposed
>> to be applied after automatic implicit conversions. And since LHS of
>> assignment is not one of the contexts excluded from array type decay,
>> said decay is already sufficient to prevent assignment to arrays.
>
> The Rationale says "the fact that a[i] is a modifiable lvalue while a is
> not has puzzled many students of the language. A more precise
> description was incorporated in C89 in the hope of combatting this
> confusion."
>
> I have a vague memory that this wording is connected to a subtle issue
> with functions that return values of struct type, where the struct
> contains an array member. But I can't remember what the issue was.

I think that case is separate from what we're discussing here, though of
course they're both related to the odd way C treats array expressions.

This thread is about lvalues that are of array type.

The struct return issue is about expressions of array type that are not
lvalues (something that's no longer possible as of C11, I think).

In C90 and C99, if a function returns a struct with a member of array
type and you refer to the name of that member:
func().array_member
then that's an expression of array type which is converted (in most
contexts) to a pointer to the initial element of "the array object".
The problem: In that specific case there is no array object (a function
call yields a value, not an object). C11 resolved that by inventing an
object with "temporary lifetime". There are cases other than function
calls where this shows up; the assignment, comma, and conditional
operators can yield non-lvalues of struct type.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Array is an non-modifiable lvalue - where does it matter?

<sctt7r$88g$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17528&group=comp.lang.c#17528

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Fri, 16 Jul 2021 23:27:06 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <sctt7r$88g$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me> <20210716145835.570@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 17 Jul 2021 06:27:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c1c7040f8271367d127ce45a0ba30031";
logging-data="8464"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18tHiEoI42WpNh8qLFKJvIo"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:JhsvlMrVbMJ0b0EFqDlaX4r8Uik=
In-Reply-To: <20210716145835.570@kylheku.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 17 Jul 2021 06:27 UTC

On 7/16/2021 3:21 PM, Kaz Kylheku wrote:
> If what you are getting at is this: could a C dialect provide complete
> support for array passing, returning and assignment, while conforming
> to the current standard?
>
> The answer is no.

No, no, no, I'm not interested in that at all.

>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>> before automatic implicit conversions or after them?
>
> It looks moot. Before conversion to pointer, you have an array lvalue,
> and the requirement says that it' not modifiable. Thus, cannot assign to
> it. After conversion to pointer, you don't have an lvalue. Not
> assignable, either.
>

Yes, it is moot for the specific case of arrays.

But at the same time it intuitively looks and feels like a more general
issue. Again, what comes first: automatic implicit conversions or
constraint checks?

And even if this currently proves to be moot in all other contexts as
well, it still appears to be something kinda... too important to be left
unspecified.

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<scup4s$498$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17530&group=comp.lang.c#17530

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!news.swapon.de!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 16:23:24 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <scup4s$498$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
<875yxbth6r.fsf@bsb.me.uk>
<e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
<scrdrf$g4r$1@dont-email.me> <scshd7$r7p$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Jul 2021 14:23:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b0f80248a75d4f7695d757116cb0c7d0";
logging-data="4392"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9YMnrdnndoj85kMbbKcQDIr8dhIugdRo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
Thunderbird/68.10.0
Cancel-Lock: sha1:qDc8jhjkWjgYmU6sg4BfHLu5Fog=
In-Reply-To: <scshd7$r7p$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Sat, 17 Jul 2021 14:23 UTC

On 16/07/2021 19:59, Andrey Tarasevich wrote:
> On 7/16/2021 12:52 AM, David Brown wrote:
>>
>> The standard says "A modifiable lvalue is an lvalue that does not have
>> array type".  When applied to "a = b", this has been interpreted to mean
>> that "a" is an lvalue of array type and therefore a non-modifiable
>> lvalue, so you cannot use the assignment.  This is, AFAICS, subtly
>> incorrect - used here, "a" is converted to a non-lvalue pointer to its
>> first element.  It is not an lvalue at all, modifiable or non-modifiable.
>>
>
> That's actually part of the question I was asking originally.
>
> You are implicitly insisting that the array-to-pointer conversion should
> be applied first, and only after that the constraints of the assignment
> operator should be checked.
>

I'm not sure I'd use the word "insisting", but that is correct.

> Can you provide a reference to C standard that would indicate that it is
> supposed to be done in that specific order, and not the other way around?

Assignment is an operator, and thus the left-hand side is an expression.
6.3.2.1p3 says:

"""
Except when it is the operand of the sizeof operator, or the unary &
operator, or is a string literal used to initalize an array, an
expression that has type "array of type" is converted to an expression
with type "pointer to type" that points to the initial element of the
array object and is not an lvalue.
"""

As for the order in which the conversions are done here, I think these
come from the grammar of the language - subexpressions must be converted
before the operand using them. I can't conceive of how a language could
do anything else here, but it is given in 6.5p1 anyway. (Generated code
can do calculations in any order as long as the results are correct.)

>
> For example, C++ standard is known to use wording like "this (conversion
> | transformation | adjustment) is applied before and further (analysis |
> consideration) is performed" in order to eliminate such ambiguities.
>

Yes, but that is because in C++ you can have many implicit conversions
and thus the ordering is not clear.

> But I don't see anything like that in C standard. One can argue that it
> doesn't matter since the outcome is functionally the same either way.
> But still... the question is intended as a "language-lawyer" one.
>

Re: Array is an non-modifiable lvalue - where does it matter?

<20210717094529.447@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17533&group=comp.lang.c#17533

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 563-365-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 16:53:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <20210717094529.447@kylheku.com>
References: <scq5c5$tql$1@dont-email.me> <20210716145835.570@kylheku.com>
<sctt7r$88g$1@dont-email.me>
Injection-Date: Sat, 17 Jul 2021 16:53:46 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4ef5227146a28e9915a37e47ddc34671";
logging-data="15434"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19lyuxWFkM+6JN2QCZLFMHJBLrGmYVZdS8="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:kPiGfh+vKDWqfUvood9iMRcvALw=
 by: Kaz Kylheku - Sat, 17 Jul 2021 16:53 UTC

On 2021-07-17, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
> On 7/16/2021 3:21 PM, Kaz Kylheku wrote:
>> If what you are getting at is this: could a C dialect provide complete
>> support for array passing, returning and assignment, while conforming
>> to the current standard?
>>
>> The answer is no.
>
> No, no, no, I'm not interested in that at all.
>
>>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>>> before automatic implicit conversions or after them?
>>
>> It looks moot. Before conversion to pointer, you have an array lvalue,
>> and the requirement says that it' not modifiable. Thus, cannot assign to
>> it. After conversion to pointer, you don't have an lvalue. Not
>> assignable, either.
>>
>
> Yes, it is moot for the specific case of arrays.
>
> But at the same time it intuitively looks and feels like a more general
> issue. Again, what comes first: automatic implicit conversions or
> constraint checks?

In "array = foo", there is no implicit conversion of array. It is
an lvalue of array type and remains that way.

If the assignment were allowed, then how it would likely work is
that the "array = foo" expression, as a whole would implicitly convert
to a pointer but not "array" itself.

This is analogous to i = j = 0, j is an lvalue and stays that way.
However (j = 0) isn't an lvalue.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal

Re: Array is an non-modifiable lvalue - where does it matter?

<scv579$tag$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17534&group=comp.lang.c#17534

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 10:49:26 -0700
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <scv579$tag$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me> <20210716145835.570@kylheku.com>
<sctt7r$88g$1@dont-email.me> <20210717094529.447@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 17 Jul 2021 17:49:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c1c7040f8271367d127ce45a0ba30031";
logging-data="30032"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19rP97+CmNmP130lNRWceKz"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:baiAajcHXuNp3nECFXWMF8xdek4=
In-Reply-To: <20210717094529.447@kylheku.com>
Content-Language: en-US
 by: Andrey Tarasevich - Sat, 17 Jul 2021 17:49 UTC

On 7/17/2021 9:53 AM, Kaz Kylheku wrote:
> On 2021-07-17, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>> On 7/16/2021 3:21 PM, Kaz Kylheku wrote:
>>> If what you are getting at is this: could a C dialect provide complete
>>> support for array passing, returning and assignment, while conforming
>>> to the current standard?
>>>
>>> The answer is no.
>>
>> No, no, no, I'm not interested in that at all.
>>
>>>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>>>> before automatic implicit conversions or after them?
>>>
>>> It looks moot. Before conversion to pointer, you have an array lvalue,
>>> and the requirement says that it' not modifiable. Thus, cannot assign to
>>> it. After conversion to pointer, you don't have an lvalue. Not
>>> assignable, either.
>>>
>>
>> Yes, it is moot for the specific case of arrays.
>>
>> But at the same time it intuitively looks and feels like a more general
>> issue. Again, what comes first: automatic implicit conversions or
>> constraint checks?
>
> In "array = foo", there is no implicit conversion of array.

That's not true. In `array = foo` the left-hand side is implicitly
converted to pointer type (under assumption that constraints are checked
after applying automatic implicit conversions).

> It is an lvalue of array type and remains that way.

That is completely false. Remember that value categories refer to
expression results, not to objects themselves.

Since simple contextless `array` expression is not excluded from
decaying contexts by 6.3.2.1/3, `array` itself (as an expression) is an
rvalue of pointer type.

The same can be said of LHS of assignment: it is an rvalue of pointer
type (again, under assumption that constraints are checked after
applying automatic implicit conversions).

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<scve2a$p8n$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17535&group=comp.lang.c#17535

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!NBiuIU74OKL7NpIOsbuNjQ.user.gioia.aioe.org.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 13:20:27 -0700
Organization: Aioe.org NNTP Server
Lines: 59
Message-ID: <scve2a$p8n$1@gioia.aioe.org>
References: <scq5c5$tql$1@dont-email.me>
NNTP-Posting-Host: NBiuIU74OKL7NpIOsbuNjQ.user.gioia.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Chris M. Thomasson - Sat, 17 Jul 2021 20:20 UTC

On 7/15/2021 1:21 PM, Andrey Tarasevich wrote:
> 6.3.2/1 says that
>
>   1 [...] A modifiable lvalue is an lvalue that does not have array
> type, [...]
>
> Based on that, arrays are non-modifiable lvalues. We all know what it
> actually means. But is there any context in the standard in which this
> non-modifiability of array lvalues would actually _matter_, would
> actually interact with some other standard requirement?
>
> One thing that comes to mind is a constraint on assignment operators
> (6.5.16/2)
>
>   2 An assignment operator shall have a modifiable lvalue as its left
> operand.
>
> So, one can combine 6.3.2/1 and 6.5.16/2 and conclude that one can't
> assign to arrays. But I believe that constraints are intended/supposed
> to be applied after automatic implicit conversions. And since LHS of
> assignment is not one of the contexts excluded from array type decay,
> said decay is already sufficient to prevent assignment to arrays.
>
> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
> before automatic implicit conversions or after them?
>
> And if the answer is "after", then is there any other context in C
> standard where non-modifiability of array lvalues would make a difference?
>

I must be missing something. Fwiw, sometimes I wrap fixed arrays in
structs just to be able to copy them via assignment:
__________________________________
#include <stdio.h>

#define FOO_N 50

struct array
{ int foo[FOO_N];
};

int main()
{ struct array data_0 = { 0 };
struct array copy_0 = data_0;

copy_0.foo[42] = 42;

printf("data_0::foo[%u] = %d\n", 42, data_0.foo[42]);
printf("copy_0::foo[%u] = %d\n", 42, copy_0.foo[42]);

return 0;
} __________________________________

Re: Array is an non-modifiable lvalue - where does it matter?

<871r7w3b9e.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17536&group=comp.lang.c#17536

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 14:01:49 -0700
Organization: None to speak of
Lines: 55
Message-ID: <871r7w3b9e.fsf@nosuchdomain.example.com>
References: <scq5c5$tql$1@dont-email.me> <20210716145835.570@kylheku.com>
<sctt7r$88g$1@dont-email.me> <20210717094529.447@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="54b9e5b9899999611d969dd6d5e30777";
logging-data="28551"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18b1B1dZlxaV41IeutgCGZv"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:derJ4ioNU18p2WWRSOmQcYXN+YU=
sha1:M9cvu7KTNCp4DE0YzkF1jjAj2u8=
 by: Keith Thompson - Sat, 17 Jul 2021 21:01 UTC

Kaz Kylheku <563-365-8930@kylheku.com> writes:
> On 2021-07-17, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>> On 7/16/2021 3:21 PM, Kaz Kylheku wrote:
>>> If what you are getting at is this: could a C dialect provide complete
>>> support for array passing, returning and assignment, while conforming
>>> to the current standard?
>>>
>>> The answer is no.
>>
>> No, no, no, I'm not interested in that at all.
>>
>>>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>>>> before automatic implicit conversions or after them?
>>>
>>> It looks moot. Before conversion to pointer, you have an array lvalue,
>>> and the requirement says that it' not modifiable. Thus, cannot assign to
>>> it. After conversion to pointer, you don't have an lvalue. Not
>>> assignable, either.
>>>
>>
>> Yes, it is moot for the specific case of arrays.
>>
>> But at the same time it intuitively looks and feels like a more general
>> issue. Again, what comes first: automatic implicit conversions or
>> constraint checks?
>
> In "array = foo", there is no implicit conversion of array. It is
> an lvalue of array type and remains that way.

I don't believe that's correct. `array` is an expression of array type
(whether it's an lvalue or not). The standard specifies three contexts
in which such an expression is not converted a pointer expression (N1570
lists 4, but it's incorrect). The LHS of an assignment is not one of
those contexts.

If the conversion did not apply, the assignment would be a constraint
violation because `array` is not a *modifiable* lvalue. But the
conversion does apply, and so the assignment is a constraint violation
because, after the conversion, `array` is a non-lvalue expression of
pointer type.

Of course it doesn't matter *why* it's a constraint violation, as long
as the implementation issues a diagnostic.

> If the assignment were allowed, then how it would likely work is
> that the "array = foo" expression, as a whole would implicitly convert
> to a pointer but not "array" itself.
>
> This is analogous to i = j = 0, j is an lvalue and stays that way.
> However (j = 0) isn't an lvalue.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: Array is an non-modifiable lvalue - where does it matter?

<scvrm9$auf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17538&group=comp.lang.c#17538

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 20:12:56 -0400
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <scvrm9$auf$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me> <20210716145835.570@kylheku.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 18 Jul 2021 00:12:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f828ca440c9d21f7f1daa84dcd541df7";
logging-data="11215"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y1r2Eho/8oOkH3ymCrYCCGWpCGN/shYg="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:s+zs71Sag5INDh1RyZC65TwQ54Q=
In-Reply-To: <20210716145835.570@kylheku.com>
Content-Language: en-US
 by: James Kuyper - Sun, 18 Jul 2021 00:12 UTC

On 7/16/21 6:21 PM, Kaz Kylheku wrote:
> On 2021-07-15, Andrey Tarasevich <andreytarasevich@hotmail.com> wrote:
>> 6.3.2/1 says that
>>
>> 1 [...] A modifiable lvalue is an lvalue that does not have array
>> type, [...]
>>
>> Based on that, arrays are non-modifiable lvalues. We all know what it
>> actually means. But is there any context in the standard in which this
>> non-modifiability of array lvalues would actually _matter_, would
>> actually interact with some other standard requirement?
>
> If what you are getting at is this: could a C dialect provide complete
> support for array passing, returning and assignment, while conforming
> to the current standard?

I doubt that he's trying to "get at" anything. As I read his message, it
appears that he found a clause in the standard whose purpose he did not
understand, and he's asking for an explanation of it. You're reading far
too much into his question.

Re: Array is an non-modifiable lvalue - where does it matter?

<scvrp8$auf$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17539&group=comp.lang.c#17539

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: jameskuy...@alumni.caltech.edu (James Kuyper)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 20:14:32 -0400
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <scvrp8$auf$2@dont-email.me>
References: <scq5c5$tql$1@dont-email.me>
<5c1d96ea-c554-4aa1-b0db-a7729027ee04n@googlegroups.com>
<875yxbth6r.fsf@bsb.me.uk>
<e6132d4c-d915-492a-a76e-2d4a2062d353n@googlegroups.com>
<scrdrf$g4r$1@dont-email.me> <scshd7$r7p$1@dont-email.me>
<scup4s$498$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 18 Jul 2021 00:14:32 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="f828ca440c9d21f7f1daa84dcd541df7";
logging-data="11215"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WA6CgyB+joUUSjKmexVgn61AZIHesYDw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:uzhvDfBqNKKoialSKXIhX37CmjU=
In-Reply-To: <scup4s$498$1@dont-email.me>
Content-Language: en-US
 by: James Kuyper - Sun, 18 Jul 2021 00:14 UTC

On 7/17/21 10:23 AM, David Brown wrote:
> On 16/07/2021 19:59, Andrey Tarasevich wrote:
....
>> You are implicitly insisting that the array-to-pointer conversion should
>> be applied first, and only after that the constraints of the assignment
>> operator should be checked.
>>
>
> I'm not sure I'd use the word "insisting", but that is correct.
>
>> Can you provide a reference to C standard that would indicate that it is
>> supposed to be done in that specific order, and not the other way around?
>
> Assignment is an operator, and thus the left-hand side is an expression.
> 6.3.2.1p3 says:
>
> """
> Except when it is the operand of the sizeof operator, or the unary &
> operator, or is a string literal used to initalize an array, an
> expression that has type "array of type" is converted to an expression
> with type "pointer to type" that points to the initial element of the
> array object and is not an lvalue.
> """
>
> As for the order in which the conversions are done here, I think these
> come from the grammar of the language - subexpressions must be converted
> before the operand using them. I can't conceive of how a language could
> do anything else here, but it is given in 6.5p1 anyway. (Generated code
> can do calculations in any order as long as the results are correct.)

It's not about the order in which any of the operations occur that
matters. It's about whether the constraints apply before or after the
conversions. Constraints are not actions, and the standard is therefore
less specific about how they are sequenced relative to actual activities.

Re: Array is an non-modifiable lvalue - where does it matter?

<87im18mnqr.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17540&group=comp.lang.c#17540

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sun, 18 Jul 2021 02:09:32 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <87im18mnqr.fsf@bsb.me.uk>
References: <scq5c5$tql$1@dont-email.me> <20210716145835.570@kylheku.com>
<sctt7r$88g$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="c51e6f5f8587429bb6f5a262ac253285";
logging-data="1723"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/S8uO3a5scQsc0Q6bcgJNUO9/cHq1Woqg="
Cancel-Lock: sha1:6zmZE5W3E1BrwDTdDfWwSFKOfrc=
sha1:DywUUQpQa7njk0I8F7HlqNIUz14=
X-BSB-Auth: 1.c403fba647400ca55e5a.20210718020932BST.87im18mnqr.fsf@bsb.me.uk
 by: Ben Bacarisse - Sun, 18 Jul 2021 01:09 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:

> On 7/16/2021 3:21 PM, Kaz Kylheku wrote:
>> If what you are getting at is this: could a C dialect provide complete
>> support for array passing, returning and assignment, while conforming
>> to the current standard?
>> The answer is no.
>
> No, no, no, I'm not interested in that at all.
>
>>> Am I right here? Is the constraint of 6.5.16/2 supposed to be applied
>>> before automatic implicit conversions or after them?
>> It looks moot. Before conversion to pointer, you have an array lvalue,
>> and the requirement says that it' not modifiable. Thus, cannot assign to
>> it. After conversion to pointer, you don't have an lvalue. Not
>> assignable, either.
>>
>
> Yes, it is moot for the specific case of arrays.
>
> But at the same time it intuitively looks and feels like a more
> general issue. Again, what comes first: automatic implicit conversions
> or constraint checks?

That the /intent/ is that the constraints apply after these conversions
is obvious from many other common situations. For example, given

int array[2];
void f(void);

both *array and f() would be constraint violations unless the
conversions in section 6.3.2.1 are applied first.

> And even if this currently proves to be moot in all other contexts as
> well, it still appears to be something kinda... too important to be
> left unspecified.

Is it clearly specified? I don't know. I've never thought it could be
taken any other way, but the fact that you were not sure makes this
obviously wrong.

--
Ben.

Re: Array is an non-modifiable lvalue - where does it matter?

<scvvrv$s1r$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17541&group=comp.lang.c#17541

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: andreyta...@hotmail.com (Andrey Tarasevich)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 18:24:14 -0700
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <scvvrv$s1r$1@dont-email.me>
References: <scq5c5$tql$1@dont-email.me> <scsiq3$ens$1@dont-email.me>
<scsk02$v8i$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 18 Jul 2021 01:24:15 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="463f7e0f8ab1199d8009c1947b3f21a1";
logging-data="28731"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19OneEQrauM8Ju8Ab/NRkJP"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101
Thunderbird/78.12.0
Cancel-Lock: sha1:aEJO1KH8vJDExWML/HoADKoc7rE=
In-Reply-To: <scsk02$v8i$1@dont-email.me>
Content-Language: en-US
 by: Andrey Tarasevich - Sun, 18 Jul 2021 01:24 UTC

On 7/16/2021 11:43 AM, Andrey Tarasevich wrote:
> On 7/16/2021 11:22 AM, James Kuyper wrote:
>>
>> I have a vague memory that this wording is connected to a subtle issue
>> with functions that return values of struct type, where the struct
>> contains an array member. But I can't remember what the issue was.
>>
>
> The issue(s) stem from the combination of the following bits and pieces:
>
>   1. Function return is always an rvalue
>   2. Member array of an rvalue struct object is also an rvalue
>   3. The result of unary '*' is always an lvalue. And, say, `[]` is
> defined through unary '*' and '+'.
>
> 2 and 3 conflict with each other.
> ...

> C99 cops out of this latter problem by stating that the behavior is
> undefined in this case.

I see that I fell victim to the same confusion I'm carefully trying to
avoid.

Of course, there's no real conflict between 2 and 3. Value category is a
property of an expression, not a property of an object. There's nothing
wrong with having two different expressions that expose the same
underlying object as an lvalue and as an rvalue at the same time.

C89/90 apparently did not want to introduce the concept of "temporary
lifetime". That's why it simply prohibited access to arrays inside
rvalue structs.

C99 decided that this is unnecessarily restrictive, and now we have
lvalue access to elements of arrays inside rvalue structs. But still C99
is afraid to allow us to modify these elements. Granted, the use cases
will always be pronouncedly contrived

#include <stdio.h>

struct S { int a[10]; };

struct S foo()
{
return (struct S) { 0 };
}

int main()
{
int *p;
p = foo().a, p[5] = 42, printf("%d\n", p[5]); // undefined behavior
}

but in some corner cases it could have been useful...

--
Best regards,
Andrey Tarasevich

Re: Array is an non-modifiable lvalue - where does it matter?

<87wnpo1eq9.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=17543&group=comp.lang.c#17543

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: Array is an non-modifiable lvalue - where does it matter?
Date: Sat, 17 Jul 2021 20:29:50 -0700
Organization: None to speak of
Lines: 77
Message-ID: <87wnpo1eq9.fsf@nosuchdomain.example.com>
References: <scq5c5$tql$1@dont-email.me> <scsiq3$ens$1@dont-email.me>
<scsk02$v8i$1@dont-email.me> <scvvrv$s1r$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="0e87c24faf3c265a0047f0634906d7ad";
logging-data="11763"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/FkqgZQJ7YWFc+qIymeMOw"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:W+rHGwDa9OyHaqjPm/A0YOAi2V8=
sha1:n763866Ax+SmJn6J4owuappmqEw=
 by: Keith Thompson - Sun, 18 Jul 2021 03:29 UTC

Andrey Tarasevich <andreytarasevich@hotmail.com> writes:
> On 7/16/2021 11:43 AM, Andrey Tarasevich wrote:
>> On 7/16/2021 11:22 AM, James Kuyper wrote:
>>>
>>> I have a vague memory that this wording is connected to a subtle issue
>>> with functions that return values of struct type, where the struct
>>> contains an array member. But I can't remember what the issue was.
>>>
>> The issue(s) stem from the combination of the following bits and
>> pieces:
>>   1. Function return is always an rvalue
>>   2. Member array of an rvalue struct object is also an rvalue
>>   3. The result of unary '*' is always an lvalue. And, say, `[]` is
>> defined through unary '*' and '+'.
>> 2 and 3 conflict with each other.
>> ...
>
>> C99 cops out of this latter problem by stating that the behavior is
>> undefined in this case.
>
> I see that I fell victim to the same confusion I'm carefully trying to
> avoid.
>
> Of course, there's no real conflict between 2 and 3. Value category is
> a property of an expression, not a property of an object. There's
> nothing wrong with having two different expressions that expose the
> same underlying object as an lvalue and as an rvalue at the same time.
>
> C89/90 apparently did not want to introduce the concept of "temporary
> lifetime". That's why it simply prohibited access to arrays inside
> rvalue structs.

Unless I'm missing something, C89/C90 didn't *prohibit* access to arrays
inside rvalue structs. The idea was simply overlooked (and it is rather
obscure). It says that an array expression is converted to a pointer
expression that points to the initial element of "the array object",
overlooking the rare cases when there is no array object to point to.
It was a bug in the standard, fixed in C11.

> C99 decided that this is unnecessarily restrictive, and now we have
> lvalue access to elements of arrays inside rvalue structs. But still
> C99 is afraid to allow us to modify these elements. Granted, the use
> cases will always be pronouncedly contrived
>
> #include <stdio.h>
>
> struct S { int a[10]; };
>
> struct S foo()
> {
> return (struct S) { 0 };
> }
>
> int main()
> {
> int *p;
> p = foo().a, p[5] = 42, printf("%d\n", p[5]); // undefined behavior
> }
>
> but in some corner cases it could have been useful...

That was resolved in C11, not C99. C11 introduced the concept of
"temporary lifetime" for non-lvalue expressions of structure or union
type with an array member. See N1570 6.2.4p8.

I can't think of any cases where allowing modification of an object with
temporary lifetime would be useful. In your admittedly contrived
example, if you wanted the struct S object to be persistent, you could
arrange for that easily enough.

(Another approach might have been to add a rule saying that foo().a
yields a pointer of type `const int*`, but that's a bit ugly.)

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor