DOCUMENT:Q149696 30-JUL-2001 [visualc] TITLE :FIX: Bad Code Generated for Inline Assembly Using Enumerators PRODUCT :Microsoft C Compiler PROD/VER::4.1 OPER/SYS: KEYWORDS:kbcode kbVC410bug kbVC420fixkbbuglist kbfixlist ====================================================================== ------------------------------------------------------------------------------- The information in this article applies to: - Microsoft Visual C++, version 4.1 ------------------------------------------------------------------------------- SYMPTOMS ======== When you use an enumerator in an inline assembly statement, incorrect code will be generated for the enumerator value. The following code fragment demonstrates the problem: void main() { enum { FALL=1, WINTER, SPRING, SUMMER }; _asm { mov eax, WINTER ; <--- This will incorrectly load 'eax' ; with something other than 2. } } STATUS ====== Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ 32- bit Edition version 4.2. MORE INFORMATION ================ This problem will impact developers that are using the Microsoft Windows 95 Device Driver Kit (DDK) or other tools that are used to build VXD drivers with C/C++. The DDK provides C/C++ header files that use enumerators and inline assembly in this fashion. There are no workarounds for this problem. The following are possible alternatives if the developer is at liberty to modify the source code: void main() { #define FALL 1 #define WINTER 2 #define SPRING 3 #define SUMMER 4 _asm { mov eax, WINTER } } The drawback to the #define directive method is that it has no scope. Another method that does have scope is this: void main() { const int FALL = 1, WINTER = 2, SPRING = 3, SUMMER = 4; _asm { mov eax, WINTER } } Additional query words: InLineAsmIss ====================================================================== Keywords : kbcode kbVC410bug kbVC420fix kbbuglist kbfixlist Technology : kbVCsearch kbAudDeveloper kbVC410 Version : :4.1 Issue type : kbbug Solution Type : kbfix ============================================================================= THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY. Copyright Microsoft Corporation 2001.