BUG: /G3 /AL Options Generate Bad Code For Comparison to Long

ID: Q115847

1.00 1.50 WINDOWS kbtool kbbuglist

The information in this article applies to:

SYMPTOMS

The assembly code generated for the sample code below has an incorrect comparison to a long. This occurs when the /G3 compiler option (generate 386 instructions) is used in conjunction with the /AL option (large memory model).

RESOLUTION

There are two possible workarounds.

1. use the /G2 compiler option (generate 286 code), rather than the /G3

   compiler option

   -or-

2. reverse the comparison expression. For example, in the sample code
   below, change the if statement to:

      if( (base == 10L) && (num < 0L) )

  • The if statement above will generate the correct 386 code.

    STATUS

    Microsoft has confirmed this to be a problem in the C++ compiler for MS-DOS, versions 8.0 and 8.0c. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.

    MORE INFORMATION

    The following is a sample that demonstrates the code generation problem. The incorrect assembly code can be examined by looking at the .COD file produced.

    Sample Code

    /* Compile options: /AL /Fc /G3 /c
     */ 
    
    int go(long num, long base)
    
    {
       int negative;
       if( (num < 0L) && (base == 10L) )          // comparison
       {
    /*
    
    ; from the .cod file ; ; Line 7
         cmp   DWORD PTR [bp+8],655360;000a0000H  // should be 10 not 655360
         jne   SHORT $I107
         cmp   WORD PTR [bp+12],0
         jne   SHORT $I107
    */ 
          negative = 1;
          num = -num;
       }
       else negative = 0;
    
       return(negative);
    
    }

    int main()
    
    {
        long num, base;
    
        num = base = 10L;
        return(go(num, base));
    
    }

    Additional reference words: 1.00 1.50 8.00 8.00c KBCategory: kbtool kbbuglist KBSubcategory: CodeGen Keywords : kb16bitonly

    Last Reviewed: July 23, 1997