The memset( ) Function

Chapter 9 - Arrays

Visual C++ 6: The Complete Reference
Chris H. Pappas and William H. Murray, III
  Copyright 1998 The McGraw-Hill Companies

Array Index Out of Bounds
There is a popular saying that states, “You don’t get something for nothing.” This holds true with array types. The “something” you get is faster executing code at the expense of the “nothing,” which is zero boundary checking. Remember, since C and C++ were designed to replace assembly language code, error checking was left out of the compiler to keep the code lean. Without any compiler error checking, you must be very careful when dealing with array boundaries. For example, the following program elicits no complaints from the compiler, yet it can change the contents of other variables or even crash the program by writing beyond the array’s boundary:
/*
*   norun.c
*   Do NOT run this C program
*  Copyright (c) Chris H. Pappas and William H. Murray, 1998
*/

#include <stdio.h>

#define iMAX 10
#define iOUT_OF_RANGE 50

main( )
{
 int inot_enough_room[iMAX], index;

 for(index=0; index < iOUT_OF_RANGE; index++)
   inot_enough_room[index]=index;

 return(0);
}

Books24x7.com, Inc 2000 –  


Visual C++ 6(c) The Complete Reference
Visual Studio 6: The Complete Reference
ISBN: B00007FYGA
EAN: N/A
Year: 1998
Pages: 207

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net