title: Get the largest signed integer type in C++
body: <p>Let's say I have to accept a size as an argument to an interface which deals with arrays. For e.x.</p>
  
  <pre><code>void doSomethingRelatedToArrays(const size_t length)
  </code></pre>
  
  <p>Here, I used <code>size_t</code> with the following in mind:</p>
  
  <ul>
  <li>length must always be positive</li>
  <li><code>size_t</code> is always typedef-ed to the largest unsigned integer type in the system. <code>std::size_t</code> can store the maximum size of a theoretically possible object of any type.</li>
  </ul>
  
  <p>However, I should not use unsigned types in my interfaces because the client can pass in a negative number, which is implicitly converted to an unsigned number and I do not have any way of validating it in my method. Refer to Scott Meyer's article on this subject <a href="http://www.aristeia.com/Papers/C++ReportColumns/sep95.pdf" rel="nofollow noreferrer">here</a>.</p>
  
  <p>So, I should pass in signed integer type to the API. But how can I get the largest signed integer type in the system? Is there any typedef similar to <code>size_t</code> which is signed? Or should I just use <code>size_t</code> instead?</p>