KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q43700: C: Loop Optimization Causes Internal Compiler Error

Article: Q43700
Product(s): See article
Version(s): 5.10   | 5.10
Operating System(s): MS-DOS | OS/2
Keyword(s): ENDUSER | | mspl13_c
Last Modified: 26-SEP-1989

The two programs shown below demonstrate the following internal
compiler error. The error occurs in the Microsoft C Optimizing
Compiler Version 5.10, when compiled with loop and alias relaxation
optimization enabled, and either the compact or large-memory models.

    fatal error C1001 : Internal Compiler Error
       (compiler file '@(#)regMD.c:1.117', line 1861)
       Contact Microsoft Technical Support

An easy workaround is to not use the /Oal combination, or use a
different memory model.

The first program is as follows:

int flags = 0;                         /* change to int j, flags = 0 */
void main(int argc, char *argv[])
{
    int i,j;                           /* change to int i; */
    for (i=1; i<argc; i++)
        switch(argv[i][0]) {
            case '-':
                for (j=1; argv[i][j]; j++)
                    switch (argv[i][j]) {
                        case 'a' : flags |= 0x1; break;
                        case 'b' : flags |= 0x2; break;
                        case 'c' : flags |= 0x4; break;
                        case 'd' : case '?': default: flags = 0x8; break;
                    }
       }
}

To work around this problem, move the declaration of "j" outside of
main().

The second program is as follows:

typedef struct  LINE {
        short   l_used;
        char    l_text[1];
}       LINE;

typedef struct  WINDOW {
        LINE *w_dotp;
}       WINDOW;

extern  WINDOW  *curwp;

void main()
{
        int    nicol;
        int    c;
        int    i;

        for (i=0; i< curwp->w_dotp->l_used; ++i) {
                c = curwp->w_dotp->l_text[i]&0xFF;
                if (c!=' ' && c!='\t')
                        break;
                if (c == '\t')
                        nicol |= 0x07;
                ++nicol;
        }
}

You can work around this problem by adding a new variable of type
pointer to WINDOW and then using this pointer in the assignment to the
variable "c". For example, you can change the for loop in the code to
appear as follows:

        for (i=0; i< curwp->w_dotp->l_used; ++i) {
              WINDOW *foo1;
                foo1 = curwp;
                c = foo1->w_dotp->l_text[i]&0xFF;

                if (c!=' ' && c!='\t')
                        break;
                if (c == '\t')
                        nicol |= 0x07;
                ++nicol;

Microsoft is researching this problem and will post new information as
it becomes available.

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 1986-2002.