Here's my C code:
char *ptr = "0xfff1342809062Cac";
char *pEnd;
long long value = strtoll(ptr, &pEnd, 0);
printf("%lld\n", value);
printf("errno: %d\n", errno);
I compiled it with gcc-8.3.0, and the output is:
9223372036854775807
errno: 34
I'm confused that strtoll gives an unexpected value and set errno to 34.
This behaviour is correct. On your system the maximum value for long long, i.e. LLONG_MAX is 9223372036854775807.
The value in your string is larger than this; and the specified behaviour if the value is out of range and too big is: return LLONG_MAX and errno is set to ERANGE (presumably 34 on your system).
Perhaps consider using strtoull and an unsigned long long return value , since that string would fit in that data type.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With