The result magnitude implementation-specific, so it has no portable meaning and you should not rely on it. The memcmp()
function is only guaranteed to return a positive, negative, or zero value.
The reason why it is allowed to have any value is so memcmp()
can be defined like this:
// Types changed to "char" to simplify code.
int memcmp(const unsigned char *x, const unsigned char *y, size_t n)
{
for (size_t i = 0; i < n; i++) {
int diff = x[i] - y[i];
if (diff)
return diff;
}
But it can also be implemented by using, e.g., SSE, and the return value will be different.