I'm using Dev-C++ 5.11 and using compiler options to compile to C11. I'm having trouble using the scanf_s
function. I've tried <stdio.h>
as well as <stdlib.h>
.
Is there anything in the standard library that includes this?
I'm using Dev-C++ 5.11 and using compiler options to compile to C11. I'm having trouble using the scanf_s
function. I've tried <stdio.h>
as well as <stdlib.h>
.
Is there anything in the standard library that includes this?
I'm having trouble using the scanf_s function. I've tried <stdio.h> as well as <stdlib.h>. Is there anything in the standard library that includes this?
scanf_s()
is part of C since C11. It is in "Annex K, Bounds-checking interfaces" and it is optional. Test __STDC_LIB_EXT1__
for its availability.
An implementation that defines
__STDC_LIB_EXT1__
shall conform to the specifications in this annex. C17dr § K.2 2
scanf_s
and other Annex K functions are effectively Microsoft-only.
As noted by others, they're optional functions, but the only widely-used development environment that implements them are those from Microsoft, and Microsoft's implementation is non-conforming and not portable.
Per N1967 - Field Experience With Annex K — Bounds Checking Interfaces](http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1967.htm):
...
Available Implementations
Despite the specification of the APIs having been around for over a decade only a handful of implementations exist with varying degrees of completeness and conformance. The following is a survey of implementations that are known to exist and their status.
While two of the implementations below are available in portable source code form as Open Source projects, none of the popular Open Source distribution such as BSD or Linux has chosen to make either available to their users. At least one (GNU C Library) has repeatedly rejected proposals for inclusion for some of the same reasons as those noted by the Austin Group in their initial review of TR 24731-1 N1106]. It appears unlikely that the APIs will be provided by future versions of these distributions.
Microsoft Visual Studio
Microsoft Visual Studio implements an early version of the APIs. However, the implementation is incomplete and conforms neither to C11 nor to the original TR 24731-1. For example, it doesn't provide the set_constraint_handler_s function but instead defines a _invalid_parameter_handler _set_invalid_parameter_handler(_invalid_parameter_handler) function with similar behavior but a slightly different and incompatible signature. It also doesn't define the abort_handler_s and ignore_handler_s functions, the memset_s function (which isn't part of the TR), or the RSIZE_MAX macro.The Microsoft implementation also doesn't treat overlapping source and destination sequences as runtime-constraint violations and instead has undefined behavior in such cases.
As a result of the numerous deviations from the specification the Microsoft implementation cannot be considered conforming or portable.
NB the conclusion: As a result of the numerous deviations from the specification the Microsoft implementation cannot be considered conforming or portable.
So if you use these functions on a Microsoft compiler, you'll wind up writing non-portable code.