scanf()中的反转参数

Mik*_*ike 13 c gcc compiler-errors

我(很快)编写了一些代码并意外地将参数反转为scanf():

char i[] = "ABC1\t";
scanf(i, "%s");
Run Code Online (Sandbox Code Playgroud)

编译gcc -Werror -Wall -Wextra并没有抱怨这一点.显然,这段代码不起作用,但为什么没有gcc通知我,我颠倒了论点?它不能检测到i不是格式字符串,或者第二个参数不是可存储类型吗?

编辑
感谢您的洞察力,看起来我找到了答案,-Wformat旗帜上有一个扭曲,使这个"捕获"(在下面张贴以供参考)

Mik*_*ike 17

哈!我找到了.用-Wformat=2旗帜击中gcc就抓住了它.

发布信息供他人参考:

这是我找到的旗帜列表

-Wformat Check calls to printf and scanf, etc., to make sure that the arguments supplied have types appropriate to the format string specified...

我曾经假设它-Wall已经-Wformat存在,它确实存在,但是关于我刚发现的东西真正重要的部分:

-Wformat is included in -Wall. For more control over some aspects of format checking, the options -Wformat-y2k, -Wno-format-extra-args, -Wno-format-zero-length, -Wformat-nonliteral, -Wformat-security, and -Wformat=2 are available, but are not included in -Wall.


Lyt*_*yth 8

我想它不应该.

int scanf ( const char * format, ... );
Run Code Online (Sandbox Code Playgroud)

i通常转换为a const char*,所有其余参数只是"省略号",在编译时无法检查.