要在 scanf() 的扫描集中包含一个连字符作为元素,它应该是列表中的第一个字符还是最后一个字符?

To include a hyphen as element in scanset of scanf(), should it be first or last character in the list?

scanf()%[-A-B234abc]%[A-B234abc-] 的正确扫描集格式说明符语法是什么?我在Whosebug上找不到答案,下面两个链接给出了矛盾的答案:

cplusplusreference: 不是第一个字符的破折号 (-) 在某些库实现中可能会产生不可移植的行为。

beez: 要匹配连字符,请将其设为集合中的最后一个字符:%[A-C-].

根据 n1570(C11 标准草案)和 n1256(C99 标准草案),

7.21.6.2 The fscanf function

[...]

  1. The conversion specifiers and their meanings are:

        [...]

        [       [...]
                If a - character is in the scanlist and is not the first, nor the second where the first character is a ^, nor the last character, the behavior is implementation-defined.