man sscanf: %d is deprecated in C or glibc?

How come %d is deprecated? It seem that all int specifiers are deprecated.

They are not deprecated in the sense that that term is ordinarily used in software documentation. There is no plan for their removal from the language and there are no direct replacements. The ISO committee responsible for maintaining the language standard has not expressed any opinion that they should be avoided, though there are indeed workarounds available to avoid their use.

The deprecation notices on some Linux manual pages that you are asking about constitute an inappropriate liberty taken by the maintainer of that version of the documentation. It is explained in the BUGS section of the same page:

Numeric conversion specifiers

Use of the numeric conversion specifiers produces Undefined
Behavior for invalid input. See C11 7.21.6.2/10
⟨https://port70.net/%7Ensz/c/c11/n1570.html#7.21.6.2p10⟩. This is
a bug in the ISO C standard, and not an inherent design issue
with the API. However, current implementations are not safe from
that bug, so it is not recommended to use them. Instead,
programs should use functions such as strtol(3) to parse numeric
input. This manual page deprecates use of the numeric conversion
specifiers until they are fixed by ISO C.

The manual page maintainer is both unfortunately opinionated and atypically aggressive. It is a somewhat controversial opinion that it constitutes a bug in the standard for the affected functions have undefined behavior for invalid input. It is a valid opinion that that is a good reason to avoid numeric conversion specifiers, but that author is not empowered to deprecate the functions in the sense that readers of the manual page would typically understand. The conventional approach to a situation like this would to be add references to the BUGS section at appropriate places in the manual text, possibly even with a brief explanatory note. Deprecation labels are not that, no matter how they are explained elsewhere in the document.

With that said, the scanf-family functions are overall difficult to use correctly. Some around here are prone to recommend avoiding them entirely, and that should certainly be considered. If you do avoid them, then that moots the issue.

Leave a Comment