Re: Accessing result of assignment
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 09/06/04
- Next message: Jack Klein: "Re: define a data type of 1 bit size"
- Previous message: CBFalconer: "Re: scanf pushes back two chars?"
- In reply to: Barry Schwarz: "Accessing result of assignment"
- Next in thread: junky_fellow: "Re: Accessing result of assignment"
- Reply: junky_fellow: "Re: Accessing result of assignment"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 6 Sep 2004 14:40:49 -0400 (EDT)
On Mon, 6 Sep 2004, Barry Schwarz wrote:
>
> Could someone please explain what section 6.5.16-4 means
>
> "The order of evaluation of the operands is unspecified. If an attempt
> is made to modify the result of an assignment operator or to access it
> after the next sequence point, the behavior is undefined."
>
> I understand the order of evaluation part.
>
> d = b*b-4*a*c;
> if (d>0) ...
>
> This is pretty common code and obviously not undefined behavior if the
> variables are properly defined and assigned values. But it seems that
> the if statement attempts to access the result of the previous
> assignment operator after the end of statement sequence point as
> described in the quote. What am I misinterpreting?
The result of the assignment operator is discarded. It never gets
used. What gets used in the 'if' statement is the value of the object
'd'. (That 'd' was assigned to in the previous statement has absolutely
no relevance.)
The condition
if ((d = b*b-4*a*c) > 0) ...
uses the result of the assignment operator in an expression, but it
uses it /before/ the next sequence point, so it's okay.
HTH,
-Arthur
- Next message: Jack Klein: "Re: define a data type of 1 bit size"
- Previous message: CBFalconer: "Re: scanf pushes back two chars?"
- In reply to: Barry Schwarz: "Accessing result of assignment"
- Next in thread: junky_fellow: "Re: Accessing result of assignment"
- Reply: junky_fellow: "Re: Accessing result of assignment"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|