Why does string::compare return an int?
<p>Why does <a href="http://www.cplusplus.com/reference/string/string/compare/"><code>string::compare</code></a> return an int instead of a smaller type like <code>short</code> or <code>char</code>? My understanding is that this method only returns -1, 0 or 1. </p>

<p>Second part, if I was to design a compare method that compares two objects of type <code>Foo</code> and I only wanted to return -1, 0 or 1, would using <code>short</code> or <code>char</code> generally be a good idea?</p>

<p>EDIT: I've been corrected, <code>string::compare</code> does not return -1, 0, or 1, it in fact returns a value >0, &lt;0 or 0. Thanks for keeping me in line guys.</p>

<p>It seems like the answer is roughly, there is no reason to return a type smaller than int because return values are "rvalues" and those "rvalues" don't benefit from being smaller than type int (4 bytes). Also, many people pointed out that the registers of most systems are probably going to be of size int anyway, since these registers are going to be filled weather you give them a 1, 2 or 4 byte value, there is no real advantage to returning a smaller value.</p>

<p>EDIT 2: In fact it looks like there may be extra processing overhead when using smaller datatypes such as alignment, masking, etc. The general consensus is that the smaller datatypes exist to conserve on memory when working with a lot of data, as in the case of an array. </p>

<p>Learned something today, thanks again guys!</p>
