Re: Regarding assignment to struct

Liste des GroupesRevenir à l c 
Sujet : Re: Regarding assignment to struct
De : david.brown (at) *nospam* hesbynett.no (David Brown)
Groupes : comp.lang.c
Date : 29. May 2025, 20:05:37
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <101ab61$me2$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11
User-Agent : Mozilla Thunderbird
On 29/05/2025 14:19, Andrey Tarasevich wrote:
On Tue 5/6/2025 2:35 AM, David Brown wrote:
>
N3096 6.2.4p2: "If a pointer value is used in an evaluation after
the object the pointer points to (or just past) reaches the end of
its lifetime, the behavior is undefined. The representation of a
pointer object becomes indeterminate when the object the pointer
points to (or just past) reaches the end of its lifetime."
>
>
It seems clear to me that "pc" has an indeterminate value after the expression assigning, since it points to an object with temporary lifetime.
>
And attempting to use the value of an object with automatic storage while it has an indeterminate value is undefined behaviour.
 Again, this makes no sense. Please, pay attention to the code and the corrections made after the initial version (e.g. usage of comma operator). No, the value of `pc` is not indeterminate, and no, there's no undefined behavior in the above version of the code.
 
As far as I can see, simply reading the value in "pc" to print it out is UB according to the C standards.  It is clearly going to be a harmless operation on most hardware, but there are processors where pointer registers are more complicated than simple linear addresses - they can track some kind of segment structure describing the range of a data block, or permissions for access to the data, and such structures could have been deactivated or deallocated when the temporary lifetime object died.  Even attempting to read the value of the pointer, without dereferencing it, would then cause some kind of fault or trap.
 Again, irrelevant. In the above code the temporary object does not die during the entire period when pointer `pc` is used in any way.
 
I posted later that I had made a mistake, and not noticed the use of the comma instead of a semicolon.
Why are you dredging up an outdated thread?  I made an error three weeks ago, and realised the mistake shortly afterwards.  What do you expect me or anyone else to learn from that now, after all this time?

Date Sujet#  Auteur
25 Jul 25 o 

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal