小编Mar*_*zer的帖子

如何规避GCC中的格式截断警告?

我收到以下gcc格式 - 截断警告:

test.c:8:33: warning: ‘/input’ directive output may be truncated writing 6 bytes into a region of size between 1 and 20 [-Wformat-truncation=]
snprintf(dst, sizeof(dst), "%s-more", src);
                             ^~~~~~
test.c:8:3: note: ‘snprintf’ output between 7 and 26 bytes into a destination of size 20
snprintf(dst, sizeof(dst), "%s-more", src);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Run Code Online (Sandbox Code Playgroud)

像这样的代码:

char dst[20];
char src[20];
scanf("%s", src);
snprintf(dst, sizeof(dst), "%s-more", src);
printf("%s\n", dst);
Run Code Online (Sandbox Code Playgroud)

我知道它可能会被截断 - 但这正是我首先使用snprintf的原因.有没有办法让编译器明白这是预期的(不使用编译指示或-Wno格式截断)?

c format gcc gcc-warning

12
推荐指数
3
解决办法
8776
查看次数

用于编译项目的所有 C 或 C++ 头文件的列表

我想知道编译一个带有多个结果二进制文件的整个 C/C++ 项目的所有代码文件的路径。我知道https://github.com/rizsotto/Bear等人,您可以将其环绕在“make”调用中,并告诉您 gcc/g++ 调用,但它们当然只向我显示已编译的 C/C++ 文件- 我怎样才能找出编译需要哪些头文件并最终出现在生成的二进制文件之一中?

c c++ gcc g++

-2
推荐指数
2
解决办法
875
查看次数

标签 统计

c ×2

gcc ×2

c++ ×1

format ×1

g++ ×1

gcc-warning ×1