Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Studio Team System
C6200

warning C6200: index <name> is out of valid index range <min> to <max> for non-stack buffer <variable>

This warning indicates that an integer offset into the specified array exceeds the maximum bounds of that array. This defect might cause random behavior or crashes.

One common cause of this defect is using the size of an array as an index into the array. Because C/C++ array indexing is zero-based, the maximum legal index into an array is one less than the number of array elements.

The following code generates this warning because the for loop exceeds the index range:

int buff[14]; // array of 0..13 elements
void f()
{
   for (int i=0; i<=14;i++) // i exceeds the index
   {
     buff[i]= 0; // warning C6200 
     // code...
   }
}

To correct both warnings, use correct array size as shown in the following code:

int buff[14]; // array of 0..13 elements
void f()
{
   for ( int i=0; i < 14; i++) // loop stops when i < 14 
   {
     buff[i]= 0; // initialize buffer
    // code...
   }
}
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker