BUG: Watch Expression Evaluation Gives Unexpected ValueLast reviewed: July 13, 1995Article ID: Q118395 |
The information in this article applies to:
SYMPTOMSExpressions evaluated in the watch window result in incorrect values, and no overflow warnings are given.
CAUSEThe FORTRAN expression evaluator, which calculates the value of expressions that are typed into the watch window, uses the same data type to store intermediate values as it does to store the terms in the expression. For example, if all of the terms in an expression were INTEGER*2, then the expression will be evaluated with INTEGER*2 arithmetic. It is very common for an overflow to occur in subexpressions of an expression, even if the final value can be stored in INTEGER*2. The result of a calculation following this convention is incorrect because this is not the way expressions are evaluated in FORTRAN code.
RESOLUTIONAvoid creating expressions that could overflow. The most reliable way to do this is to avoid using INTEGER*2 and INTEGER*1. You can make the subexpressions of an expression be calculated in INTEGER*4 by forcing one of the terms to be stored as INTEGER*4. To do this, use the function INT4() on a term in the subexpression.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft FORTRAN PowerStation for MS-DOS, versions 1.0 and 1.0a, and the Microsoft FORTRAN PowerStation 32 for Windows NT, version 1.0. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe expression "i1*i2/i3" in the sample code below has a subexpression "i1*i2", which causes an overflow in INTEGER*4. This causes an incorrect evaluation of the expression. To demonstrate the problem, perform the following steps:
ian = 3157 i1*i2/i3 = -291 int4(i1)*i2/i3 = 3157 Sample CodeC Compile options needed: Debug Mode
integer*2 i1,i2,i3,ian i1 = 500 i2 = 120 i3 = 19 ian = i1*i2/i3 print *, ian end |
Additional reference words: 1.00 1.00a
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |