The strtol() function doesn't set errno to 0 in case of successful convertion. Currently, I'm using the following code to make it work: errno = 0; strtol(....); if (errno) { /// report an error } gcc --version gcc (GCC) 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)
that is often the case errno has no valid meaning unless an error occured
Intersting. And 1) why did it always work before in GCC? 2) why it works in all the other compilers (I'm doing cross-platform development here) - gcc, borland, msvc++, etc ..? 3) how I suppose to know if the conversion was ok? In my case, after the successful conversion the value of errno was 'file not found'.. The return value of that function can only reflect overflow/underflow. 4) the interesting part. If the prior call to strtol sets errno to EINVAL, and we call it again, successfully - but the errno is still EINVAL? (In reply to comment #1) > that is often the case > > errno has no valid meaning unless an error occured >
read the manpage The strtol() function returns the result of the conversion, unless the value would underflow or overflow. If an underflow occurs, strtol() returns LONG_MIN. If an overflow occurs, strtol() returns LONG_MAX.