What Is Bounds Checking?

Article Details
  • Written By: Mary McMahon
  • Edited By: Nancy Fann-Im
  • Last Modified Date: 18 December 2019
  • Copyright Protected:
    Conjecture Corporation
  • Print this Article
Free Widgets for your Site/Blog
Bhutan didn’t have any paved roads until 1962; now, the country is using plastic waste to blacktop those roads.  more...

January 23 ,  1973 :  US President Nixon announced that a peace settlement had been reached in Vietnam.  more...

Bounds checking is a procedure to make sure a variable conforms with the bounds of an array. In programming, variables that fall outside the bounds can create problems with the operation of a program and may freeze it or cause an error. For some types of programming languages, this procedure is standard to protect the integrity of operations and arrays, while in others it may need to be actively performed on an order from the operator.

In a simple example of bounds checking, if a programmer has an array ranging between two and 14 and tries to insert 16 as a variable, it does not fit. It would be out of bounds, and depending on what the array is used for, might create a serious error. For example, if the array represents available memory, an out of bounds variable would result in an illegal operation; the array doesn't allow it, and the system might create an error with the stored data or be unable to store it at all.


In bounds checking, it is possible to determine if a variable falls within an allowable range, or to evaluate an index to see if it fits within the stated bounds. If there is a problem, the program can flag it, allowing the programmer to fix it before attempting an operation that will fail. This can prevent the development of bad references and other issues that may arise when the bounds of an array are ignored. Computer errors related to violations of the bounds can be challenging to fix, and techniques to avoid them will make a program run more smoothly.

Handling of bounds checking in various programming languages varies. As people learn programming, they learn more about the full features and functions available and decide how best to use them, given the type of work they do. Numerous products can perform bounds checking if it is not native to a programming language. Some of these are available for free, and may not work with all systems or languages, but can provide a good start.

A failure to perform bounds checking can have consequences in the future, although the programmer may not notice the problem immediately. Debugging processes may include bounds checking to look for obvious issues. Multiple passes of debugging are typically part of the development process, to catch as many problems as possible before software is released to the general public. A poorly prepared product may be prone to error and could generate consumer frustration.


You might also Like


Discuss this Article

Post your comments

Post Anonymously


forgot password?