PRB: Code Generation Error May Occur w/ /Ol & /AC, /AL, or /AH

ID Number: Q72392

6.00 6.00a 6.00ax | 6.00 6.00a

MS-DOS | OS/2

buglist6.00 buglist6.00a buglist6.00ax fixlist7.00

Summary:

SYMPTOMS

The Microsoft C Compiler versions 6.0, 6.0a, and 6.0ax may generate

incorrect code when loop optimization (/Ol) is used with compact

(/AC), large (/AL), or huge (/AH) memory model.

RESOLUTION

If you can compile with small (/AS) or medium (/AM) model, the

correct code is generated. If this is not possible, compiling with

the quick compile option (/qc), turning off loop optimization, or

adding another optimization (such as /Og) also eliminates the

problem.

STATUS

Microsoft has confirmed this to be a problem in C versions 6.0,

6.0a, and 6.0ax. This problem has been corrected in C/C++ version 7.0.

More Information:

The sample program below illustrates this problem. The compiler

generates code that always tests the last character in the array. As a

result, the "match" count is not 1 and the program prints "Failed".

Sample Code

-----------

/* Compile options needed: /AL /Ol

*/

int _cdecl printf(const char *, ...);

int num = 3, i, match = 3;

char ch, ch_array[3] = {'A', 'B', 'S'};

int main(void)

{

for( i = 0 ; i < num ; i++ )

{

ch = ch_array[i];

if ( ch == 'E' || ch == 'A' || ch == 'B' )

{

match--;

}

}

printf("\n%s\n", match == 1 ? "Passed" : "Failed");

return( match == 1 ? 0 : 1 );

}

Additional reference words: 6.00 6.00a 6.00ax