Re: Accessing result of assignment
From: Michael Wojcik (mwojcik_at_newsguy.com)
Date: 09/10/04
- Next message: csudha: "Difference between Structure & Union"
- Previous message: Mark A. Odell: "Re: malloc and free"
- In reply to: Old Wolf: "Re: Accessing result of assignment"
- Next in thread: Christian Bau: "Re: Accessing result of assignment"
- Reply: Christian Bau: "Re: Accessing result of assignment"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 10 Sep 2004 13:28:36 GMT
In article <843a4f78.0409100326.41d984ba@posting.google.com>, oldwolf@inspire.net.nz (Old Wolf) writes:
>
> int c;
> memset(x, c = 0, sizeof x);
That looks OK to me. N869 6.5.16p4 says that accessing the result of
the assignment operator *after the next sequence point* causes UB;
that's what made
if ((a=b) == f(c))
undefined (because there's a sequence point after the arguments to f
are evaluated). In your example, the result of the assignment
operator (in "c = 0") is accessed before the sequence point that
occurs when all of memset's arguments have been evaluated, because
accessing it is part of evaluating memset's arguments; hence no UB.
So, curiously enough,
if ((a=b) == c)
is legal, but eg
if ((a=b) == (c,d))
is not, because of the sequence point caused by evaluating the first
operand of the comma operator.
OK, now someone should point out where I got it wrong...
(I'm glad Mark re-posted his question. This was a tricky one, and
I certainly hadn't noticed it before.)
-- Michael Wojcik michael.wojcik@microfocus.com The lark is exclusively a Soviet bird. The lark does not like the other countries, and lets its harmonious song be heard only over the fields made fertile by the collective labor of the citizens of the happy land of the Soviets. -- D. Bleiman
- Next message: csudha: "Difference between Structure & Union"
- Previous message: Mark A. Odell: "Re: malloc and free"
- In reply to: Old Wolf: "Re: Accessing result of assignment"
- Next in thread: Christian Bau: "Re: Accessing result of assignment"
- Reply: Christian Bau: "Re: Accessing result of assignment"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|