Omar Maredly
Omar Maredly

Reputation: 3

sprintf_s problems. It worked on Windows, but not on Xcode

sprintf_s(colorBuffer, 255, "%.2X", getAlpha());
result.append(colorBuffer);

The error is:

Use of undeclared identifier 'sprintf_s'

Upvotes: 0

Views: 834

Answers (1)

Codo
Codo

Reputation: 78915

sprintf_s is part annex K of the C11 standard, titled "bounds-checking interfaces". Annex K is optional.

Annex K hasn't been successful. N1967 Field Experience With Annex K — Bounds Checking Interfaces stated in 1995:

Despite more than a decade since the original proposal and nearly ten years since the ratification of ISO/IEC TR 24731-1:2007, and almost five years since the introduction of the Bounds checking interfaces into the C standard, no viable conforming implementations has emerged. The APIs continue to be controversial and requests for implementation continue to be rejected by implementers.

The authors even propose:

... that Annex K be either removed from the next revision of the C standard, or deprecated and then removed.

The only major compiler to implement it (or part of it) is Visual Studio. No luck with Xcode (based on clang) or gcc.

Upvotes: 3

Related Questions