Liste des Groupes | Revenir à l c |
On Tue 5/6/2025 2:35 AM, David Brown wrote:I posted later that I had made a mistake, and not noticed the use of the comma instead of a semicolon.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.>>
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.
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.
Les messages affichés proviennent d'usenet.