title: Array bounds checking techniques in C or Objective-C
body: <p>My goal is to prevent index out of bounds conditions for the lower bound when using a variable as a subscript to an array. In other words, I'd like to limit the integer variable values to >= 0. Sort of similar to an absolute value, except instead of making a negative number positive, it would make a negative number zero.</p>
  
  <p>Is there any better method of doing this than using a macro such as:</p>
  
  <pre><code>#define gte0(value) (value &lt; 0) ? 0 : value
  </code></pre>
  
  <p>and then wrapping my variables representing an index with this macro when I access an array element? Is there a standard practice bounds checking other than doing it manually in every place in your code before you access an array element with a variable representing the index?</p>
  
  <p>I'm looking for any solutions in C or Objective-C.</p>
  
  <p>Thanks!</p>