9

While answering a question that made use of some functions (sscanf_s and sprintf_s) that I thought were not standard C, Daniel Fischer brought to my attention that the functions in question were defined in Annex K.

I understand generally that normative means it helps define the standard. But, an annex to the C Standard has traditionally been treated as informative only. Annex K is labeled as normative in the C11 Standard. It defines "safe" functions.

Does this mean a compiler that doesn't provided these functions does not conform to the C11 Standard?

I only have the draft C11 Standard available to me, but it states that Annex K is normative, but the library section of the standard makes no mention of the functions discussed in Annex K. A note in the definition of runtime-constraint seems to imply Annex K defines an extension.

Does a normative Annex only define an optional extension?

Deduplicator
  • 44,692
  • 7
  • 66
  • 118
jxh
  • 69,070
  • 8
  • 110
  • 193

2 Answers2

17

Annex K is optional; it says so itself.

See K.2 paragraph 2:

An implementation that defines __STDC_LIB_EXT1__ shall conform to the specifications in this annex.

with a footnote:

Implementations that do not define __STDC_LIB_EXT1__ are not required to conform to these specifications.

And paragraph 3 says:

Subclause K.3 should be read as if it were merged into the parallel structure of named subclauses of clause 7.

which is why it's not necessary to mention it in the library section, clause 7 (or at least the authors of the standard didn't feel it was necessary).

As of C11, an implementation that defines __STDC_LIB_EXT1__ must define it as 201112L; both N1570 and the released C11 standard got this wrong, but it was fixed in a Technical Corrigendum.

Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
  • Thanks. I poked around the other normative annexes and see that all of them provide some macro to declare their availability, except for Annex D. Does this mean Annex D is required? – jxh May 22 '13 at 20:27
  • Yes, 6.4.2.1, which defines the syntax of identifiers, unconditionally refers to Annex D. – Keith Thompson May 22 '13 at 20:29
5

It's "normative" in the sense that an implementation claiming to support Annex K must meet the requirements therein. It's not mandatory.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • So a program that is written using features defined only in a conforming annex of the standard is not a strictly conforming program? – jxh May 22 '13 at 20:16
  • 4
    @user315052 "A strictly conforming program can use conditional features (see 6.10.8.3) provided the use is guarded by an appropriate conditional inclusion preprocessing directive using the related macro." – Daniel Fischer May 22 '13 at 21:38
  • @DanielFischer: Gotcha, thanks. I figured that out after seeing Keith Thompson's answer. – jxh May 22 '13 at 21:44