strtoull and long long arithmetic
任何人都可以解释该程序的输出以及如何解决该问题吗?
1 2 3 4 5 | unsigned long long ns = strtoull("123110724001300", (char **)NULL, 10); fprintf(stderr,"%llu\ ", ns); // 18446744073490980372 |
是否包含
如果省略
1 2 3 4 5 6 7 8 9 10 | #include <stdio.h> #include <stdlib.h> int main(void) { unsigned long long ns = strtoll("123110724001300", (char **)NULL, 10); printf("%llu\ ", ns); return(0); } |
省略标题,我得到了您的结果。标头,我得到了正确的答案。
32位和64位编译器。
如注释中所述,在没有声明strtoll()的情况下,编译器会处理
要查看更多信息,请查看十六进制输出:
1 2 | 123110724001300 0x00006FF7_F2F8DE14 Correct 18446744073490980372 0xFFFFFFFF_F2F8DE14 Incorrect |
手动插入下划线...
如果要长无符号长整数,为什么不使用strtoull?
我无法解释这种行为。但是,在Cygwin
1 2 3 4 5 6 7 8 9 | #include <stdio.h> #include <stdlib.h> int main(void) { unsigned long long ns = strtoull("123110724001300", NULL, 10); fprintf(stderr,"%llu\ ", ns); return 0; } |
打印
1 2 | E:\\Home> t.exe 123110724001300 |