scanf
failuresAuthors: Joseph Myers
Date: 2025-03-07
Submitted against: C23
Status: Open
Cross-references: 1012
C23 7.23.6.3 (The fscanf
function) describes failures as follows:
Failures are described as input failures (due to the occurrence of an encoding error or the unavailability of input characters), or matching failures (due to inappropriate input).
Unsupported specific width length modifiers (for example, %w123d
if
there is no int123_t
or int_least123_t
type and w123
is not
implementation-defined to be supported anyway) are defined as error
conditions for both printf
and scanf
functions (rather than
undefined behavior). But is such an error an input failure or a
matching failure? Or is it some new kind of failure, requiring the
quoted dichotomy to be updated?
The same issue also applies for fwscanf
.
No specific change is proposed here to address this issue since appropriate wording would depend on direction from the committee on what kind of failure this should be.
Comment from Issues list maintainer on 2025-09-01:
At the August 2025 (Brno) meeting of WG14, the committee gave direction to treat this as a matching failure rather than a third kind of failure.
In reflector message 33426, the issue submitter suggested possible wording for this.
In C23 7.23.6.3 (The fscanf
function), insert:
Failures are described as input failures (due to the occurrence of an encoding error or the unavailability of input characters), or matching failures (due to inappropriate input). If the implementation does not support a specific width length modifier, this is a matching failure.
Under Returns, remove:
Otherwise, the function returns the number of input items assigned, which can be fewer than provided for, or even zero, in the event of an early matching failure
or if the implementation does not support a specific width length modifier.
Make the same changes in C23 7.31.2.3 (The fwscanf
function).
These changes would supersede those for scanf
functions in issue
1012.
The wording was further discussed in reflector messages 33429 and 33435.