Can anyone explain the output of this program and how I can fix it?
unsigned long long ns = strtoull("123110724001300", (char **)NULL, 10);
fprintf(stderr, "%llu\n", ns);
// 18446744073490980372
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Do you have
<stdlib.h>included?I can reproduce on MacOS X if I omit
<stdlib.h>.Omit the header, I get your result.
Include the header, I get the correct answer.
Both 32-bit and 64-bit compiles.
As noted in the comments, in the absence of a declaration for strtoll(), the compiler treats it as a function returning int.
To see more of what goes on, look at the hex outputs:
Manually inserted underscores…