FIX: Problems Using Parentheses to Denote Array Subscripts

Last reviewed: September 18, 1997
Article ID: Q115437
1.00 1.50 | 1.00
MS-DOS    | WINDOWS NT
kbtool kbfixlist kbbuglist

The information in this article applies to:

  • The Microsoft C/C++ Compiler (CL.EXE) included with:

        - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
        - Microsoft Visual C++ 32-bit Edition, version 1.0
    

SYMPTOMS

Compiling the sample code below with Visual C++ 32-bit Edition causes the compiler to generate the following error message:

     fatal error C1001: INTERNAL COMPILER ERROR
     (compiler file 'msc1.cpp', line 602)

The compiler should instead generate the following error:

     error C2064: term does not evaluate to a function

Compiling the sample code with Visual C++, version 1.5, under Windows NT gives the following error message:

     fatal error C1001: internal compiler error
     (compiler file 'msc1.cpp', line 585)

Again, "error C2064: term does not evaluate to a function" should display.

When the code below is compiled with Visual C++, versions 1.0 and 1.5 under Windows 3.1, no errors are generated. The compiler effectively ignores the erroneous line. If we compile at warning level 4 (CL /W4), the following warning is generated:

     warning C4100: 'push_this' : unreferenced formal parameter

This warning shows that the erroneous line was ignored.

CAUSE

Incorrectly compiled code uses parentheses () instead of brackets [] to denote array subscripts.

RESOLUTION

Fix the code by changing the parentheses to brackets.

STATUS

Microsoft has confirmed this to be a bug in the products listed at the beginning of this article. This bug was corrected in C/C++ compiler version 9.0, included in Visual C++ 32-bit Edition, version 2.0.

Sample Code

      // Compile options needed:    none
      #include <iostream.h>

      class stack_class {
           int stack_data[10];
           int stack_ptr;
      public:
           void init(void);
           int push(int push_this);
      };

      void stack_class::init(void) {stack_ptr = -1;};

      int stack_class::push(int push_this)
      {
           if (stack_ptr >= 99)
                return(0);

           //ERROR: (++stack_ptr) - Change to [++stack_ptr]
           stack_data(++stack_ptr) = push_this;
                return(1);
      };

      void main()
      {
           stack_class stack;

           stack.push(100);
      }


Additional reference words: 1.00 1.50 8.00 8.00c
KBCategory: kbtool kbfixlist kbbuglist
KBSubcategory: CPPIss
Keywords : CPPIss kbbuglist kbfixlist kbtool
Version : 1.00 1.50 | 1.00
Platform : MS-DOS NT WINDOWS
Solution Type : kbfix


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.

Last reviewed: September 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.