Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #1859
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: Pre And Post Increment Operator Output |
| Date | 2012-06-23 01:15 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <js31tp$obe$1@dont-email.me> (permalink) |
| References | <8404c4f1-a3b7-46b7-ad9c-17de265f9aee@googlegroups.com><js02hp$jsl$1@dont-email.me> <js03uf$sb3$1@dont-email.me><js092m$pov$1@dont-email.me> <lnipek8bri.fsf@nuthaus.mib.org><js1gf5$l7v$1@dont-email.me><0.06d3eacd14619c86d384.20120622143458BST.87ehp7o4fx.fsf@bsb.me.uk><js21jb$963$1@dont-email.me><7MudnTZhnIs6EnnSnZ2dnUVZ_qCdnZ2d@earthlink.com><js27pl$h7c$1@dont-email.me><0.0b3aeb4b00dfdccbd115.20120622205336BST.87395nnmwv.fsf@bsb.me.uk><js2l17$cd9$1@dont-email.me> <0.6a8ba340e934c61ead30.20120622231916BST.87wr2zm1ln.fsf@bsb.me.uk> |
"Ben Bacarisse" <ben.usenet@bsb.me.uk> wrote in message
news:0.6a8ba340e934c61ead30.20120622231916BST.87wr2zm1ln.fsf@bsb.me.uk...
> "BartC" <bc@freeuk.com> writes:
>>>>>> result of i=(++i)+(++i)+(++i), when i starts at 0
>> Maybe the OP in the original thread had a Java background. Or maybe he
>> just
>> decided the common-sense result was 6, and wanted to know why C didn't
>> agree.
> But you know C's rules, so why did say the value *ought* to be 6. What
> was that about?
But I said 'ought', not 'should'. The '6' was the value that might
reasonably have been expected, *before* it was put through C. I wasn't
suggesting the C language was doing anything wrong by not giving that
answer.
It was a reasonable expectation, because put through any simplistically
generated code, that what's most likely to come out. This was a beginner,
and likely his/her thought processes were similar to mine when attempting to
valuate the expression on it's own merits.
As an example of it's kind, it was less convoluted than some of them, and
didn't depend so much on evaluation order.
A beginner could equally have asked why:
unsigned int a,b,c;
a=2000000000;
b=3000000000;
c=a+b;
printf("%u\n", c);
gives the answer 705032704, rather than 5 billion. And I might have said:
"I agree, it ought to be 5000000000" before going on to explain why it gives
what is apparently the wrong answer.
> Did you want to re-start the debate about the sequence
> point rules? Did you want to propose a new semantics for C expressions?
No and No.
--
Bartc
Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar
Re: Pre And Post Increment Operator Output "BartC" <bc@freeuk.com> - 2012-06-22 16:02 +0100
Re: Pre And Post Increment Operator Output Patricia Shanahan <pats@acm.org> - 2012-06-22 08:30 -0700
Re: Pre And Post Increment Operator Output "BartC" <bc@freeuk.com> - 2012-06-22 17:49 +0100
Re: Pre And Post Increment Operator Output Patricia Shanahan <pats@acm.org> - 2012-06-22 10:36 -0700
Re: Pre And Post Increment Operator Output "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org> - 2012-06-23 09:57 +0100
Re: Pre And Post Increment Operator Output Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-22 20:53 +0100
Re: Pre And Post Increment Operator Output "BartC" <bc@freeuk.com> - 2012-06-22 21:35 +0100
Re: Pre And Post Increment Operator Output Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-22 23:19 +0100
Re: Pre And Post Increment Operator Output "BartC" <bc@freeuk.com> - 2012-06-23 01:15 +0100
Re: Pre And Post Increment Operator Output Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-06-22 17:44 +0100
csiph-web