Do I need to cast the result of strtol to int?

Posted by Kristo on Stack Overflow See other posts from Stack Overflow or by Kristo
Published on 2010-03-11T14:36:13Z Indexed on 2010/03/11 17:54 UTC
Read the original article Hit count: 146

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about c++

Related posts about best-practices