FIX: C2664 When Array Is Passed as a Parameter to a Function

Last reviewed: September 19, 1997
Article ID: Q143083
The information in this article applies to:

  - The Microsoft C/C++ Compiler (CL.EXE) included with:
    - Microsoft Visual C++, 32-bit Edition, versions 4.0, 4.1, 4.2

SYMPTOMS

The compiler will generate the following error when you pass a multiple subscript array to a function that expects a const of the same type of array:

   error C2664: 'Func2' : cannot convert parameter 1 from 'int [4][4]' to
   'const int [][4]' (new behavior; please see help)

RESOLUTION

Don't declare the parameter to be 'const' in the function definition.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ version 5.0.

MORE INFORMATION

Sample Code to Demonstrate Problem

   /* Compile options needed: None
   */

   typedef int Matrix1[4];
   typedef int Matrix2[4][4];

   void Func1( const Matrix1 ) {}

   // Remove const in the following statement to work around

   void Func2( const Matrix2 ) {}

   void main()
   {
      Matrix1 a = {1,2,3,4};
      Matrix2 b = {1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4};

      Func1( a );
      Func2( b );   // C2664 here
   }

Keywords          : CPPIss vcbuglist400 vcfixlist500 kbtool
Version           : 4.0 4.1 4.2
Platform          : NT WINDOWS
Issue type        : kbbug
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 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.