Microsoft KB Archive/33720

QuickC Loop Optimization Generates Bad Code PSS ID Number: Q33720 Article last modified on 10-12-1988 PSS database name: S_QuickC

1.01

MS-DOS

Summary: QuickC generates a bad code when the sample source code below is compiled in memory with optimization on. The problem lies in the (b = b->ptr) != NULL expression; the generated code is bad with optimization on. To work around the problem, simplify the expression as follows:

b = b->ptr; if( b != NULL ) …

instead of the following:

if( (b = b->ptr) != NULL ) …

Microsoft has confirmed this to be a problem in Version 1.01. We are researching this problem and will post new information as it becomes available.

More Information: The following the sample source code demonstrates the problem:


 * 1) include  void main(void); struct test { struct test *ptr; } aa, bb;

void main { struct test a, b;

a = &aa; b = &bb;

a->ptr = NULL; b->ptr = a; /* Note: The problem lies with optimization in loops.

If you use a &quot;for&quot;, &quot;while( 1 )&quot;, or a &quot;do { ... } while( 1 )&quot;

Results differ when compiled with OPTIMIZATION ON.
 * / while( 1 ) if( (b = b->ptr) != NULL ) { printf( “This worked right!” ); break; } else { printf( “This worked wrong!” ); break; } }

Copyright Microsoft Corporation 1988.