Re: Possible contradiction between JLS and Sun's Java compiler
- From: "Chris Uppal" <chris.uppal@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 9 Feb 2006 21:05:05 -0000
Oliver Wong wrote:
<quote>[...]
a=b=c means a=(b=c), which assigns the value of c to b and then assigns
the value of b to a.
</quote>
However, a friend of mine said when they disassembled the code
produced by javac essentially says "read c; duplicate; write b; write a;"
which seems to contradict what the JLS claims.
The following code will not compile under JDK1.4.2 or 1.5.0.
==========
class Abc
{
static void
method()
{
double a;
float b;
double c = 27.3;
a = b = c;
}
}
==========
The compiler won't accept it without a cast of c to float. With the cast it
(1.4 and 1.5) produce the bytecode you'd expect (with converstions from double
to float and back again). Note, btw, that b takes up 1 stack slot while a and
c take up 2 each -- which makes it hard to see how the compiler could "get
away" with generating incorect code.
FWIW, the actual disassembly is:
ldc2_w 27.3
dstore_3
dload_3
d2f
dup
fstore_2
f2d
dstore_0
return
Perhaps your friend has a more complicated example ?
-- chris
.
- Follow-Ups:
- Re: Possible contradiction between JLS and Sun's Java compiler
- From: Oliver Wong
- Re: Possible contradiction between JLS and Sun's Java compiler
- References:
- Possible contradiction between JLS and Sun's Java compiler
- From: Oliver Wong
- Possible contradiction between JLS and Sun's Java compiler
- Prev by Date: Re: Use JFrame and a canvas
- Next by Date: Re: Possible contradiction between JLS and Sun's Java compiler
- Previous by thread: Re: Possible contradiction between JLS and Sun's Java compiler
- Next by thread: Re: Possible contradiction between JLS and Sun's Java compiler
- Index(es):
Relevant Pages
|