INFO: C2466 Error When Allocating an Array of Length 0

Last reviewed: September 4, 1997
Article ID: Q87015
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52 - Microsoft Visual C++ 32-bit Edition, versions 1.0, 2.0, 4.0, 5.0

SUMMARY

When you use Microsoft C/C++, the constant expression that you use to allocate or declare an array must be an integral type greater than zero. If not, the following error will occur:

   C2466: Cannot allocate an array of constant size 0

The following examples are some ways this error can occur:

   int *p = new X[0];        // error
   C *aC = new [int_var] C;  // error
   int a[0];                 // error
   int func(char *[0]);      // error

NOTE: This does not apply to Visual C++, 32-bit Edition, version 2.0 and later.

If you use the Microsoft extensions (/Ze), an array declaration with a zero subscript is legal for a class, structure, or union member. For more information about valid zero-sized arrays, search the Visual C++ online documentation for the topic "Unsized Arrays."


Additional query words: 8.00 8.00c 9.00 9.10
Keywords : CPPIss
Version : MS-DOS:7.0; WINDOWS:1.0,1.5,1.51,1.52; WINDOWS NT:1.0,2.0,2.1,4.0,5.0
Platform : MS-DOS NT WINDOWS
Issue type : kberrmsg kbinfo


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 4, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.