Microsoft KB Archive/30561

Bad Code Generation for /Ol PSS ID Number: Q30561 Article last modified on 05-23-1988 PSS database name: S_QuickC

1.01

MS-DOS

Summary: QC generates the following bad code when the sample source below is compiled with loop optimization (/Ol):

mov word ptr [outfile], di

Since di contains zero at this point, it destroys the pointer to the file OUTFILE. The problem does not occur if optimization is turned off. Microsoft is researching this problem and will post new information as it becomes available.

More Information:


 * 1) include 

int main(int argc, char **argv) { int c, col = 0; char tmp = “untab.tmp”; FILE infile,*outfile;

if (argc != 2) { fprintf(stderr,&quot;Syntax -- UNTAB filespec\n&quot;); return(1); }   if ((infile = fopen(argv[1],&quot;r&quot;)) == NULL) { fprintf(stderr,&quot;File not found\n&quot;); return(1); }   if ((outfile = fopen(tmp,&quot;w&quot;)) == NULL) { fprintf(stderr,&quot;Unable to open temporary file\n&quot;); return(1); }   while ((c = fgetc(infile)) != EOF) { if (c == '\t') { do { fputc(' ',outfile); col++; }                   while ((col & 7) != 0); } else { fputc(c,outfile); col = (c == '\n') ? 0 : col + 1; }   }    fputc(0x1a,outfile); }

Copyright Microsoft Corporation 1988.