Hi Kay-Victor,
just looked into the compiler to see what happens here. Roughly spoken
it happens the following (it is quite tricky to find these things out as
there is nearly no documentation) :
- the arithmetic expression is being evaluated on 32bit base even
shortints are only 16bits
- the comparison is done by using the right hand intermediate datatype
which is dword in this case ( which is wrong I admit, internally the
32bit registers are used and the values in there are just dwords ) I you
example a value of 0xfffff3 is used for the comparison and this is the
reason while the comparison fails
If you turn it the other way round ( nB - nC ) <= nA it works because
the result of (nB-nC) get converted to SHORTINT before the comparison
takes place because the right hand part results in the datatype SHORINT.
Another, abstruse way, to get around the problem is to use
IF nA > SHORTINT(DWORD((nB - nC ))) ....
I have checked the old versions as well and this problem is there at
least since 2.0 ....
Regards
Meinhard
Am 27.05.2013 17:53, schrieb
kvste...@web.de:
> FUNCTION Start()
>
> LOCAL nA, nB, nC AS SHORTINT
>
> nA := 748
> nB := 22
> nC := 35
>
> IF nA > ( nB - nC )
> ? "748 is greater than (22 - 35)"
> ELSE
> ? "748 is not greater than (22 - 35). Oops!"
> ENDIF
>
> _Wait("")