The information in this article applies to:
SYMPTOMSThe Microsoft C/C++ compilers listed above may fail to detect a constant expression that will cause a divide-by-zero error. In these situations, the Microsoft C compiler version 6.xx may ignore the error entirely and instead use the value zero for the expression. The Microsoft C/C++ compiler version 7.0 and those included with all versions of Visual C++ may not generate an error at compile-time, but the resulting application should produce a run-time error, either on the command line as or in an Application Error message window (dialog box) with the text
CAUSE
The Microsoft C Compiler version 6.xx does not correctly handle constant
propagation in all cases where optimizations are performed. Thus, when it
evaluates constant expressions, it may not detect a divide-by-zero error,
but instead use zero as the result of the expression. This, in turn,
precludes any run-time errors.
RESOLUTIONTo work around the problem in C 6.0, you must declare the code in such a way as to disable the constant propagation optimization of the compiler. This will ensure that the division takes place at run time and then the divide-by-zero interrupt may occur. The following are methods to do this:
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. MORE INFORMATION
Because dividing by 0 (zero) results in an undefined value, the Intel chip
issues a specific interrupt (Int 0) to trap this error. This interrupt
can, in turn, be processed by an application in an appropriate manner. By
default, the Microsoft run-time libraries install an interrupt handler.
When interrupted by a divide-by-zero error, this handler either writes a
message to stdout or activates an Application Error message box and then,
in both cases, terminates the program.
This is important because the elimination of the division from the generated code means that a run-time error will not be generated. The Microsoft C Compiler version 6.xx may not generate the C2124 error. This means that a divide-by-zero error may be occurring which is not detected at compile time, and the optimization prevents it from being detected at run time. Instead, the compiler uses the value zero as the result. The program example below illustrates this problem. The Microsoft C Compiler version 6.xx generates code to load a zero at run time instead of generating an error message indicating that a possible division by zero is going to be performed. As described above, this also prevents a R6003 error from being generated at run time. The Microsoft C/C++ compiler version 7.0 and all versions included with Visual C++ generate code that performs a division by zero at run-time. The error is trapped and the user is informed appropriately. Sample Code
Additional query words: 8.00 8.00c 9.00 10.00 10.10
Keywords : kbCompiler kbVC100bug kbVC200bug kbVC210bug kbVC400bug kbVC410bug kbVC500bug kbVC600bug |
Last Reviewed: February 2, 2000 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |