The following C++ program calls strtoul
of negative 1. Since no negative numbers are representable in any unsigned type, I had expected this to fail and return 0
If no valid conversion could be performed, a zero value is returned.
but instead a large positive number is returned
#include <cstdlib>
#include <iostream>
int main () {
{char s[] = "-1";
for (int b=0; b<17; ++b)
std::cout << "strtoul (unsigned) of " << s
<< " with base arg " << b
<< ": " << strtoul(s,0,b) << std::endl;}
}
Why does strtoul not fail and return 0 for negative numbers?