Do I need to cast the result of strtol to int?
问题 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? 回答1: You may need the -Wconversion flag to turn these warnings on. However, it won't warn about long -> int , since they are the