fscanf/scanf/sscanf 禁止赋值的转换规范不是转换吗?

Is an fscanf/scanf/sscanf conversion specification with assignment suppressed not a conversion?

应该sscanf("x", "%*c%c", &(char){0}) return?

Apple 和 Godbolt 正在使用的库 return −1,这是他们的 EOF。但是,C 2018 7.21.6.7 3 告诉我们 sscanf returns “EOF 如果在第一次转换(如果有)完成之前发生输入故障。” %*c 是一个禁止赋值的转换规范。它完成,然后在 %c 完成之前发生输入失败(字符串结尾)。那么 sscanf 应该 return “分配的输入项数”,它是零。

标准中是否有任何文本告诉我们 %*c 不应被视为转换?

显然 C99 §7.19.6.2 第 15 点(和 C17 §7.21.6.2 第 15 点)告诉我们:

Trailing white space (including new-line characters) is left unread unless matched by a directive. The success of literal matches and suppressed assignments is not directly determinable other than via the %n directive.

其中“禁止分配”定义为 %* 后跟一个说明符。

所以你在你的例子中看到的似乎符合标准:你不能推断出 %*c 是否匹配,除非你使用 n 说明符来计算扫描字符的数量.

此外, by user3386109 指出“return 值仅与赋值次数有关”,并且问题中引用的 C 标准文本可能意在说“第一个赋值”而不是比“第一次转换”。