gpt4 book ai didi

使用带有 GCC 的 sscanf 解析 64 位整数的兼容方法

转载 作者:太空狗 更新时间:2023-10-29 15:26:51 30 4
gpt4 key购买 nike

我用 gcc -ansi -pedantic -Wall test.c 编译了以下 c 程序:

#include <stdio.h>
#include <stdint.h>
#define BUFFER 21
int main(int argc, char* argv[]) {
uint64_t num = 0x1337C0DE;
char str[BUFFER]; /* Safely Holds UINT64_MAX */
if(argc > 1)
sscanf(argv[1],"%llu",&num);
sprintf(str,"%llu",num);
return 0;
}

我收到以下警告:

test.c:8:5: warning: ISO C90 does not support the ‘ll’ gnu_scanf length modifier
test.c:9:3: warning: ISO C90 does not support the ‘ll’ gnu_printf length modifier

什么是符合 C90 标准的从字符串解析/打印 64 位整数的正确方法,
哪个不会生成这些警告?

最佳答案

没有。 C 90 中最大的整数类型是long,它只保证至少为 32 位。由于没有保证至少为 64 位的整数类型,因此也无法在 C90 中读取 64 位整数。当然,long 可能 是 64 位(它至少在一种实现中出现过,但不确定是不是。

关于使用带有 GCC 的 sscanf 解析 64 位整数的兼容方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17461958/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com