Do I need to cast the result of strtol to int?
- by Kristo
The following code does not give a warning with g++ 4.1.1 and -Wall.
int octalStrToInt(const std::string& s)
{
return strtol(s.c_str(), 0, 8);
}
I was expecting a warning because strtol returns a long int but my function is only returning a plain int. Might other compilers emit a warning here? Should I cast the return value to int in this case as a good practice?