Re: int a = a

Liste des GroupesRevenir à cl c 
Sujet : Re: int a = a
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 20. Mar 2025, 16:22:55
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vrhbsf$3e7sn$4@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0
On 20/03/2025 11:20, Keith Thompson wrote:
Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
Keith Thompson <Keith.S.Thompson+u@gmail.com> writes:

>
The "could have been declared with the register storage class"
seems quite odd.  And in fact it is quite odd.
>
I don't have the same reaction.  The point of this phrase is that
undefined behavior occurs only for variables that don't have
their address taken.  The phrase used describes that nicely.
Any questions related to "registerness" can be ignored, because
'register' in C really has nothing to do with hardware registers,
despite the name.
 DR 338 is explicitly motivated by an IA-64 feature that applies only to
CPU registers.  An object whose address is taken can't be stored (only)
in a register, so it can't have a NaT representation.
 The phrase used is "could have been declared with register storage class
(never had its address taken)".  Surely "never had its address taken"
would have been clear enough if CPU registers weren't a big part of the
motivation.
 
I too think the phrasing is a bit odd.
Just because a variable's address is taken, does not mean it cannot be put in a cpu register by the compiler.  If the variable is not accessed in a way that actually requires putting it in memory, then the compiler can put it in a cpu register (or otherwise optimise it).  So simply taking the address of a variable on IA-64 does not mean it cannot be in a register, and thus does not necessarily mean it cannot be NaT.  Taking the address of a variable means the variable cannot be declared "register", but it does not mean it cannot be /in/ a register.
It seems very strange to me that this is UB:
int foo1(void) {
int x;
return x;
}
while this is not :
int foo2(void) {
int x;
int * p = &x;
return x;
}
(Unfortunately, godbolt.org doesn't seem to have a gcc IA-64 compiler in its list.)
It strikes me that it would have been far simpler for the standard simply to say that using the value of an uninitialised and unassigned variable is undefined behaviour.

Date Sujet#  Auteur
18 Mar 25 * Bart's Language57bart
18 Mar 25 `* Re: Bart's Language56Waldek Hebisch
18 Mar 25  `* Re: Bart's Language55bart
18 Mar 25   `* Re: Bart's Language54Waldek Hebisch
18 Mar 25    +* Re: Bart's Language46bart
18 Mar 25    i+* Re: Bart's Language36David Brown
18 Mar 25    ii`* int a = a (Was: Bart's Language)35Kenny McCormack
18 Mar 25    ii +* Re: int a = a (Was: Bart's Language)25Janis Papanagnou
18 Mar 25    ii i+- Re: int a = a (Was: Bart's Language)1Kaz Kylheku
19 Mar 25    ii i`* Re: int a = a (Was: Bart's Language)23David Brown
19 Mar 25    ii i +- Re: int a = a (Was: Bart's Language)1Kaz Kylheku
19 Mar 25    ii i +* Re: int a = a14Keith Thompson
20 Mar 25    ii i i+* Re: int a = a12Tim Rentsch
20 Mar 25    ii i ii`* Re: int a = a11Keith Thompson
20 Mar 25    ii i ii +* Re: int a = a8David Brown
20 Mar 25    ii i ii i`* Re: int a = a7Keith Thompson
21 Mar 25    ii i ii i `* Re: int a = a6David Brown
21 Mar 25    ii i ii i  `* Re: int a = a5Keith Thompson
21 Mar 25    ii i ii i   +- Re: int a = a1David Brown
22 Mar 25    ii i ii i   `* Re: int a = a3Tim Rentsch
22 Mar 25    ii i ii i    `* Re: int a = a2Keith Thompson
28 Apr 25    ii i ii i     `- Re: int a = a1Tim Rentsch
29 Apr 25    ii i ii `* Re: int a = a2Tim Rentsch
29 Apr 25    ii i ii  `- Re: int a = a1Keith Thompson
20 Mar 25    ii i i`- Re: int a = a1David Brown
19 Mar 25    ii i +* Re: int a = a (Was: Bart's Language)5Chris M. Thomasson
20 Mar 25    ii i i`* Re: int a = a (Was: Bart's Language)4David Brown
20 Mar 25    ii i i `* Re: int a = a (Was: Bart's Language)3bart
20 Mar 25    ii i i  `* Re: int a = a (Was: Bart's Language)2David Brown
20 Mar 25    ii i i   `- Re: int a = a (Was: Bart's Language)1wij
20 Mar 25    ii i `* Re: int a = a (Was: Bart's Language)2Tim Rentsch
20 Mar 25    ii i  `- Re: int a = a (Was: Bart's Language)1David Brown
18 Mar 25    ii +* Re: int a = a (Was: Bart's Language)3David Brown
18 Mar 25    ii i`* Re: int a = a (Was: Bart's Language)2Janis Papanagnou
19 Mar 25    ii i `- Re: int a = a (Was: Bart's Language)1David Brown
19 Mar 25    ii `* Re: int a = a (Was: Bart's Language)6Tim Rentsch
19 Mar 25    ii  +* Re: int a = a2Keith Thompson
27 Apr 25    ii  i`- Re: int a = a1Tim Rentsch
19 Mar 25    ii  +- Re: int a = a (Was: Bart's Language)1David Brown
19 Mar 25    ii  `* Re: int a = a (Was: Bart's Language)2Rosario19
20 Mar 25    ii   `- Re: int a = a (Was: Bart's Language)1Tim Rentsch
20 Mar 25    i`* Re: Bart's Language9Waldek Hebisch
21 Mar 25    i `* Re: Bart's Language8Keith Thompson
22 Mar 25    i  +* Re: Bart's Language5Waldek Hebisch
22 Mar 25    i  i`* Re: Bart's Language4James Kuyper
22 Mar 25    i  i +* Re: Bart's Language2Waldek Hebisch
23 Mar 25    i  i i`- Re: Bart's Language1James Kuyper
23 Mar 25    i  i `- By definition... (Was: Bart's Language)1Kenny McCormack
27 Apr 25    i  `* Re: Bart's Language2Tim Rentsch
27 Apr 25    i   `- Re: Bart's Language1Keith Thompson
18 Mar 25    `* Re: Bart's Language7bart
20 Mar 25     `* Re: Bart's Language6Waldek Hebisch
21 Mar 25      +* Re: Bart's Language4Kaz Kylheku
21 Mar 25      i`* Re: Bart's Language3bart
21 Mar 25      i `* Re: Bart's Language2Kaz Kylheku
22 Mar 25      i  `- Re: Bart's Language1Tim Rentsch
21 Mar 25      `- Re: Bart's Language1bart

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal