Re: The MOVE problem
- From: "Judson McClendon" <judmc@xxxxxxxxxxxxx>
- Date: Fri, 2 Nov 2007 08:28:17 -0500
"Doug Miller" <spambait@xxxxxxxxxx> wrote
"Judson McClendon" <judmc@xxxxxxxxxxxxx> wrote:
there wasn't ambiguity, I said there should not be any ambiguity,
and I stand by that. Anyone implementing a C compiler that gives any other
result than 3 is a nitwit or has a bug.
Sorry, but that's just incorrect. C does *not* define how the compiler is
supposed to behave in this instance.
Compiler writers may be confused about
this, but mathematics isn't. What pre and post ++/-- do is clearly defined in
C,
No, they're not -- when they're applied more than once to the same variable in
the same statement, the resulting behavior is explicitly UNdefined.
What they do individually is defined, and given that, mathematics is sufficient to
define how they should act collectively. That is my point. There is simply no
reason to have ambiguity here. Use of prefix and postfix ++/-- is common in C,
specifically to address the kinds of thing that's going on here. Only the fact that
the same variable is referenced more than once in the same expression makes
this an issue, and mathematical rules of evaluation order are sufficient to make
it unambiguous. Not realizing and utilizing this is the 'nitwit' aspect.
and all else in this example is pure mathematics, which should be THE FINAL
standard in evaluating an arithmetic expression. :-)
OK, fine:
i = 0;
i = ... let's evaluate this expression one step at a time:
i++ {i incremented to 1}
+ ++i {i incremented to 2, intermediate value so far is 1 + 2 = 3}
+ --i {i decremented to 1}
final value = 3 + 1 = 4
Pure mathematics. :-)
But wrong C, because C's postfix i++ is clearly defined is presenting a value for
evaluation *before* 'i' is incremented (in fact, that's the only reason to have both
prefix and postfix ++/--). No ambiguity there. :-)
--
Judson McClendon judmc@xxxxxxxxxxxxx (remove zero)
Sun Valley Systems http://sunvaley.com
"For God so loved the world that He gave His only begotten Son, that
whoever believes in Him should not perish but have everlasting life."
.
- Follow-Ups:
- Re: The MOVE problem
- From: Doug Miller
- Re: The MOVE problem
- From: Michael Mattias
- Re: The MOVE problem
- References:
- Re: The MOVE problem
- From: Sergey Kashyrin
- Re: The MOVE problem
- From: Sergey Kashyrin
- Re: The MOVE problem
- From: Robert
- Re: The MOVE problem
- From: Sergey Kashyrin
- Re: The MOVE problem
- From: Judson McClendon
- Re: The MOVE problem
- From: Doug Miller
- Re: The MOVE problem
- From: Robert
- Re: The MOVE problem
- From: Jeff Campbell
- Re: The MOVE problem
- From: billious
- Re: The MOVE problem
- From: Judson McClendon
- Re: The MOVE problem
- From: Doug Miller
- Re: The MOVE problem
- Prev by Date: Re: MF COBOL Personal Edition: Differences with/without Visual Studio?
- Next by Date: Re: The MOVE problem
- Previous by thread: Re: The MOVE problem
- Next by thread: Re: The MOVE problem
- Index(es):
Relevant Pages
|