Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.programming > #1854
| From | "BartC" <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.programming |
| Subject | Re: Pre And Post Increment Operator Output |
| Date | 2012-06-22 17:49 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <js27pl$h7c$1@dont-email.me> (permalink) |
| References | (1 earlier) <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> |
"Patricia Shanahan" <pats@acm.org> wrote in message news:7MudnTZhnIs6EnnSnZ2dnUVZ_qCdnZ2d@earthlink.com... > On 6/22/2012 8:02 AM, BartC wrote: > ... >> This is all true. But I still think that if you ask for opinions as to >> the >> result of i=(++i)+(++i)+(++i), when i starts at 0, *outside the context >> of >> the C language*, then 6 is a strong contender. > > In Java, i does have a specified resulting value. The effect will be the > same as i=3*i+6. So it ends up with i=6, when i starts at zero. The case for '6' is improving.. > > I don't understand what you mean by "outside the context of the C > language". How can a code snippet have any meaning at all except in the > context of a programming language? In C specifically, such an expression has an undefined value (undefined behaviour actually). You're not allowed, apparently, to ponder what the actual result will be, nor what the expectation is, nor even what the intention of coder was. But given suitable definitions of "=" (assignment), "+", and "++" (increment in-place), which are fairly standard anyway, I think you ought to be allowed to suggest a likely value of i after: i=0 i=(++i) + (++i) + (++i) without a particular language in mind. I suggested in comp.lang.c that the result of the above ought to be 6, in line with the original poster's expectations, (before going on to explain why it might not be in C), for which I was castigated and even called evil. -- 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