Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #8971 > unrolled thread
| Started by | whl <wanghailunmail@gmail.com> |
|---|---|
| First post | 2011-10-18 20:08 -0700 |
| Last post | 2011-10-20 03:55 -0700 |
| Articles | 4 on this page of 24 — 10 participants |
Back to article view | Back to comp.lang.java.programmer
A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-18 20:08 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 04:48 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 00:54 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 09:20 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 03:38 -0700
Re: A freshman's question Lars Enderin <lars.enderin@telia.com> - 2011-10-19 17:48 +0200
Re: A freshman's question Tim Slattery <Slattery_T@bls.gov> - 2011-10-19 12:24 -0400
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:55 -0700
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:50 -0700
Re: A freshman's question Lew <lewbloch@gmail.com> - 2011-10-19 09:58 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 18:47 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:48 -0700
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 03:49 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-19 18:58 +0100
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 02:13 -0700
Re: A freshman's question Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-10-19 06:05 -0300
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-19 03:38 -0700
Re: A freshman's question Travers Naran <tnaran@gmail.com> - 2011-10-20 07:30 -0700
Re: A freshman's question Gene Wirchenko <genew@ocis.net> - 2011-10-20 10:08 -0700
Re: A freshman's question Patricia Shanahan <pats@acm.org> - 2011-10-20 18:22 +0100
Re: A freshman's question Lew <lewbloch@gmail.com> - 2011-10-20 13:59 -0700
Re: A freshman's question Joshua Cranmer <Pidgeot18@verizon.invalid> - 2011-10-20 17:38 -0500
Re: A freshman's question Roedy Green <see_website@mindprod.com.invalid> - 2011-10-19 23:56 -0700
Re: A freshman's question whl <wanghailunmail@gmail.com> - 2011-10-20 03:55 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-10-20 13:59 -0700 |
| Message-ID | <10920796.1086.1319144380777.JavaMail.geo-discussion-forums@prng5> |
| In reply to | #9040 |
Wirchenko wrote: > That comes from C. I have a question for anyone thinking it [ i = i++; ] > valid Java. What is it supposed to do of use? (If nothing, why even > use it?) I suspect the whole thing got started by someone not > understanding that ++ causes an assignment to occur. I have a question for anyone thinking it is not valid Java. Why haven't you read the Java Language Specification on this matter? <http://java.sun.com/docs/books/jls/third_edition/html/expressions.html> -- Lew
[toc] | [prev] | [next] | [standalone]
| From | Joshua Cranmer <Pidgeot18@verizon.invalid> |
|---|---|
| Date | 2011-10-20 17:38 -0500 |
| Message-ID | <j7q7sf$qhp$1@dont-email.me> |
| In reply to | #9040 |
On 10/20/2011 12:08 PM, Gene Wirchenko wrote:
> On Thu, 20 Oct 2011 07:30:31 -0700, Travers Naran<tnaran@gmail.com>
> wrote:
>
> [snip]
>
>> This is off topic, but I just recently learned that in C++, the
>> result of i=i++ is officially undefined. It's interesting a
>> question related to what I learned comes up again in a completely
>> different forum.
>
> That comes from C. I have a question for anyone thinking it valid
> Java. What is it supposed to do of use? (If nothing, why even use
> it?) I suspect the whole thing got started by someone not
> understanding that ++ causes an assignment to occur.
I'm guessing that the largest reason for this issue lies in the fact
that ++/-- is largely tied to increment/decrement addressing modes (so
*p++ would translate to "Load from p, auto-increment the pointer") [1].
In cases where it would compile to an autoincrement address mode, the
effect would take place immediately after the access, much as it does in
Java. However, on machines without this mode, it probably made more
sense to translate it into "*p; p += 1;". This is, I believe, the reason
why the C committee made |i=i++| invalid.
In contrast, Java sought to leave nothing undefined in its semantics, so
it has to pick a particular point in time at which the ++ takes place.
If you're not tied to any overt architecture, the time that makes the
most sense is to do it is immediately after getting the value (even
before its use!). That means that the following function has a
well-defined output:
int testWhen() {
int i = 0;
try {
int j = 5 / i++;
} catch (Exception e) { return i; }
return i;
}
It is 1: the increment happens before the division.
Note that the only point of |i=i++| is to point out that how and when
the increment occurs is not fully specified in C, while it is in Java.
[1] Apparently, this isn't why they were originally developed, according
to <http://cm.bell-labs.com/cm/cs/who/dmr/chist.html>. Kind of... the
PDP-7 had some memory slots which autoincremented on load, which may
have been the spark that caused them to be introduced in the language.
--
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth
[toc] | [prev] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2011-10-19 23:56 -0700 |
| Message-ID | <1dhv97lae1vhgj95pmo0pd8btte7ca3tus@4ax.com> |
| In reply to | #8971 |
On Tue, 18 Oct 2011 20:08:05 -0700 (PDT), whl <wanghailunmail@gmail.com> wrote, quoted or indirectly quoted someone who said : > I don't kown the >statement i=i++ operation sequence. This sort of code is not found in real code. It pushes the edges of the definition of the language. You would see i++ or i+=2 -- Roedy Green Canadian Mind Products http://mindprod.com It should not be considered an error when the user starts something already started or stops something already stopped. This applies to browsers, services, editors... It is inexcusable to punish the user by requiring some elaborate sequence to atone, e.g. open the task editor, find and kill some processes.
[toc] | [prev] | [next] | [standalone]
| From | whl <wanghailunmail@gmail.com> |
|---|---|
| Date | 2011-10-20 03:55 -0700 |
| Message-ID | <abd9cdc3-bae3-44b5-aa34-7bca01a76981@z28g2000pro.googlegroups.com> |
| In reply to | #9017 |
On 10月20日, 下午2时56分, Roedy Green <see_webs...@mindprod.com.invalid> wrote: > On Tue, 18 Oct 2011 20:08:05 -0700 (PDT), whl > <wanghailunm...@gmail.com> wrote, quoted or indirectly quoted someone > who said : > > > I don't kown the > >statement i=i++ operation sequence. > > This sort of code is not found in real code. It pushes the edges of > the definition of the language. > > You would see > i++ > or > i+=2 > -- > Roedy Green Canadian Mind Productshttp://mindprod.com > It should not be considered an error when the user starts something > already started or stops something already stopped. This applies > to browsers, services, editors... It is inexcusable to > punish the user by requiring some elaborate sequence to atone, > e.g. open the task editor, find and kill some processes. thank you ,I see!
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.java.programmer
csiph-web