Re: Regarding assignment to struct

Liste des GroupesRevenir à l c 
Sujet : Re: Regarding assignment to struct
De : Keith.S.Thompson+u (at) *nospam* gmail.com (Keith Thompson)
Groupes : comp.lang.c
Date : 29. May 2025, 22:36:53
Autres entêtes
Organisation : None to speak of
Message-ID : <87sekndrpm.fsf@nosuchdomain.example.com>
References : 1 2 3 4 5 6 7 8
User-Agent : Gnus/5.13 (Gnus v5.13)
Andrey Tarasevich <noone@noone.net> writes:
On Mon 5/5/2025 1:43 PM, Keith Thompson wrote:
What C90 constraint does it violate?  Both gcc and clang reject it
with "-std=c90 -pedantic-errors", with an error message "ISO C90
forbids subscripting non-lvalue array", but I don't see a relevant
constraint in the C90 standard.
>
The "constraint" in C89/90 is simply the fact that C89/90 _requires_
an lvalue (of array type) in order to apply array to pointer
conversion. Here's is the original wording:
>
  Except when it is the operand of the sizeof operator or the unary &
  operator, or is a character string literal used to initialize an
  array of character type, or is a wide string literal used to
  initialize an array with element type compatible with wchar-t, an
  *lvalue* that has type “array of type” is converted to an expression
  that has type “pointer to rype” that points to the initial element
  of the array object and is not an lvalue.
>
The presence of that "*lvalue*" requirement is what prevented up from
using `[]` operator on non-lvalue arrays in C89/90, because `[]`
critically relies on that conversion.
>
In C11 the wording has changed:
>
  Except when it is the operand of the sizeof operator, the _Alignof
  operator, or the unary & operator, or is a string literal used to
  initialize 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. If the array object has register storage class, the behavior
 is undefined.
>
Note that the "lvalue" requirement has disappeared from this
wording. That is exactly why since C99 we can apply `[]` to non-lvalue
arrays.

Yes, this was discussed in this thread several weeks ago.

A quibble: There are no implicit constraints.  All constraints
are in sections clearly marked "Constraints".  I believe that the
C90 constraint that's violated by `(a = b).a[5]` is the one that
requires the operands of [] to have pointer and integer types.
Since `(a = b).a` does not undergo array-to-pointer conversion
*in C90*, it's of array type.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
void Void(void) { Void(); } /* The recursive call of the void */

Date Sujet#  Auteur
2 May 25 * Regarding assignment to struct99Lew Pitcher
2 May 25 +- Re: Regarding assignment to struct1Keith Thompson
2 May 25 +* Re: Regarding assignment to struct13Barry Schwarz
2 May 25 i`* That depends... (Was: Regarding assignment to struct)12Kenny McCormack
3 May 25 i `* Re: That depends... (Was: Regarding assignment to struct)11Lew Pitcher
3 May 25 i  +- Re: That depends... (Was: Regarding assignment to struct)1Lawrence D'Oliveiro
3 May 25 i  +- Re: That depends... (Was: Regarding assignment to struct)1Janis Papanagnou
3 May 25 i  +* Re: That depends... (Was: Regarding assignment to struct)5Kaz Kylheku
3 May 25 i  i+* Re: That depends... (Was: Regarding assignment to struct)3Kaz Kylheku
5 May 25 i  ii`* Re: That depends... (Was: Regarding assignment to struct)2Janis Papanagnou
5 May 25 i  ii `- Re: That depends... (Was: Regarding assignment to struct)1Kaz Kylheku
4 May 25 i  i`- Re: That depends... (Was: Regarding assignment to struct)1Tim Rentsch
3 May 25 i  +- Re: That depends... (Was: Regarding assignment to struct)1James Kuyper
4 May 25 i  `* Re: That depends... (Was: Regarding assignment to struct)2Tim Rentsch
4 May 25 i   `- Re: That depends... (Was: Regarding assignment to struct)1Lew Pitcher
2 May 25 +* Re: Regarding assignment to struct2Waldek Hebisch
3 May 25 i`- Re: Regarding assignment to struct1Lew Pitcher
3 May 25 +* Re: Regarding assignment to struct66Andrey Tarasevich
3 May 25 i+* Re: Regarding assignment to struct9Lawrence D'Oliveiro
4 May 25 ii`* Re: Regarding assignment to struct8Keith Thompson
4 May 25 ii `* Re: Regarding assignment to struct7James Kuyper
4 May 25 ii  +- Re: Regarding assignment to struct1Kenny McCormack
4 May 25 ii  +- Re: Regarding assignment to struct1David Brown
4 May 25 ii  `* Re: Regarding assignment to struct4Keith Thompson
5 May 25 ii   +- Re: Regarding assignment to struct1James Kuyper
5 May 25 ii   +- Re: Regarding assignment to struct1Keith Thompson
6 May 25 ii   `- Re: Regarding assignment to struct1Tim Rentsch
3 May 25 i+- Re: Regarding assignment to struct1Lawrence D'Oliveiro
4 May 25 i`* Re: Regarding assignment to struct55Tim Rentsch
5 May 25 i `* Re: Regarding assignment to struct54Andrey Tarasevich
5 May 25 i  +* Re: Regarding assignment to struct29Michael S
5 May 25 i  i+* Re: Regarding assignment to struct27Andrey Tarasevich
5 May 25 i  ii`* Re: Regarding assignment to struct26Michael S
5 May 25 i  ii +- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  ii `* Re: Regarding assignment to struct24Andrey Tarasevich
5 May 25 i  ii  +* Re: Regarding assignment to struct4Michael S
6 May 25 i  ii  i+- Re: Regarding assignment to struct1Tim Rentsch
29 May13:11 i  ii  i+- Re: Regarding assignment to struct1Andrey Tarasevich
29 May17:57 i  ii  i`- Re: Regarding assignment to struct1James Kuyper
5 May 25 i  ii  `* Re: Regarding assignment to struct19Keith Thompson
6 May 25 i  ii   +* Re: Regarding assignment to struct2Tim Rentsch
6 May 25 i  ii   i`- Re: Regarding assignment to struct1Keith Thompson
6 May 25 i  ii   +* Re: Regarding assignment to struct3David Brown
29 May13:19 i  ii   i`* Re: Regarding assignment to struct2Andrey Tarasevich
29 May20:05 i  ii   i `- Re: Regarding assignment to struct1David Brown
6 May 25 i  ii   +* Re: Regarding assignment to struct11Waldek Hebisch
6 May 25 i  ii   i+* Re: Regarding assignment to struct7David Brown
7 May 25 i  ii   ii`* Re: Regarding assignment to struct6David Brown
29 May13:49 i  ii   ii `* Re: Regarding assignment to struct5Andrey Tarasevich
29 May15:33 i  ii   ii  +- Re: Regarding assignment to struct1Janis Papanagnou
29 May20:20 i  ii   ii  `* Re: Regarding assignment to struct3David Brown
29 May22:54 i  ii   ii   +- Re: Regarding assignment to struct1Keith Thompson
30 May09:50 i  ii   ii   `- Re: Regarding assignment to struct1David Brown
6 May 25 i  ii   i+- Re: Regarding assignment to struct1Keith Thompson
29 May13:21 i  ii   i`* Re: Regarding assignment to struct2Andrey Tarasevich
29 May15:43 i  ii   i `- Re: Regarding assignment to struct1Janis Papanagnou
29 May13:14 i  ii   `* Re: Regarding assignment to struct2Andrey Tarasevich
29 May21:56 i  ii    `- Re: Regarding assignment to struct1Keith Thompson
5 May 25 i  i`- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  +* Re: Regarding assignment to struct4Keith Thompson
5 May 25 i  i`* Re: Regarding assignment to struct3Andrey Tarasevich
8 May 25 i  i `* Re: Regarding assignment to struct2Tim Rentsch
8 May 25 i  i  `- Re: Regarding assignment to struct1David Brown
5 May 25 i  +* Re: Regarding assignment to struct17Keith Thompson
5 May 25 i  i+* Re: Regarding assignment to struct6Michael S
5 May 25 i  ii+- Re: Regarding assignment to struct1Kenny McCormack
5 May 25 i  ii+* Re: Regarding assignment to struct3Keith Thompson
5 May 25 i  iii`* Re: Regarding assignment to struct2Kaz Kylheku
6 May 25 i  iii `- Re: Regarding assignment to struct1Tim Rentsch
6 May 25 i  ii`- Re: Regarding assignment to struct1Tim Rentsch
5 May 25 i  i`* Re: Regarding assignment to struct10Tim Rentsch
5 May 25 i  i `* Re: Regarding assignment to struct9Keith Thompson
6 May 25 i  i  +* Re: Regarding assignment to struct6Nick Bowler
6 May 25 i  i  i`* Re: Regarding assignment to struct5Keith Thompson
7 May 25 i  i  i `* Re: Regarding assignment to struct4Nick Bowler
7 May 25 i  i  i  +* Re: Regarding assignment to struct2Keith Thompson
8 May 25 i  i  i  i`- Re: Regarding assignment to struct1Nick Bowler
8 May 25 i  i  i  `- Re: Regarding assignment to struct1Tim Rentsch
29 May13:36 i  i  `* Re: Regarding assignment to struct2Andrey Tarasevich
29 May22:36 i  i   `- Re: Regarding assignment to struct1Keith Thompson
5 May 25 i  +* Re: Regarding assignment to struct2Tim Rentsch
5 May 25 i  i`- Re: Regarding assignment to struct1David Brown
12 May 25 i  `- Re: Regarding assignment to struct1NotAorB
3 May 25 +* Re: Regarding assignment to struct8David Brown
5 May 25 i`* Re: Regarding assignment to struct7Muttley
5 May 25 i +- Re: Regarding assignment to struct1David Brown
5 May 25 i `* Re: Regarding assignment to struct5Keith Thompson
6 May 25 i  +- Re: Regarding assignment to struct1Muttley
6 May 25 i  +* Re: Regarding assignment to struct2David Brown
6 May 25 i  i`- Re: Regarding assignment to struct1Muttley
6 May 25 i  `- Re: Regarding assignment to struct1Michael S
4 May 25 +* Re: Regarding assignment to struct6Richard Damon
4 May 25 i`* Re: Regarding assignment to struct5Michael S
4 May 25 i +* Re: Regarding assignment to struct2Lawrence D'Oliveiro
4 May 25 i i`- Re: Regarding assignment to struct1David Brown
6 May 25 i +- Re: Regarding assignment to struct1Tim Rentsch
12 May 25 i `- Re: Regarding assignment to struct1Rosario19
4 May 25 +- Re: Regarding assignment to struct1Tim Rentsch
4 May 25 `- Re: Regarding assignment to struct1Keith Thompson

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal