gpt4 book ai didi

c - 带有 -Wformat 选项的 gcc 为 const unsigned char 打印警告

转载 作者:行者123 更新时间:2023-12-05 01:26:56 27 4
gpt4 key购买 nike

测试代码:

#include <stdio.h>

int main(int argc, char **argv) {

char buf[10];

char c[] = "%i";
unsigned char uc[] = "%i";
const char cc[] = "%i";
const unsigned char cuc[] = "%i";
const unsigned char *cucp = "%i";

sprintf(buf, (char *)c, 1);
sprintf(buf, (char *)uc, 1);
sprintf(buf, (char *)cc, 1);
sprintf(buf, (char *)cuc, 1);
sprintf(buf, (char *)cucp, 1);

return 0;
}

编译:

gcc -Wformat -o test test.c
test.c: In function ‘main’:
test.c:16:26: warning: format is a wide character string [-Wformat=]
sprintf(buf, (char *)cuc, 1);
^

Why do I get a warning for const unsigned char but not for the other types?

使用 gcc 5.4.0 和一些交叉 gcc 4.3.2 进行测试。解释可能包括不同数据类型存储在哪些段中,但我很惊讶。

最佳答案

它现在是一个确认的 gcc bug应该会尽快修复。

顺便说一句:它是在 2000 年 9 月 24 日推出的。

关于c - 带有 -Wformat 选项的 gcc 为 const unsigned char 打印警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48647554/

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