Document: WG14 N1400
Submitter: Fred J. Tydeman (USA)
Submission Date: 2009-09-18
Related WG14 documents: N1362
Subject: Headers not idempotent
7.1.2 Standard headers, in paragraph 4, has:
Standard headers may be included in any order; each may be included more than once in a given scope, with no effect different from being included only once, except that the effect of including <assert.h> depends on the definition of NDEBUG (see 7.2).
7.8 <inttypes.h> and 7.18 <stdint.h> make reference to macros that affect which macros those headers define.
So, what should an implementation do for:
and#undef __STDC_FORMAT_MACROS #include <inttypes.h> #define __STDC_FORMAT_MACROS #include <inttypes.h>
#undef __STDC_CONSTANT_MACROS #include <stdint.h> #define __STDC_CONSTANT_MACROS #include <stdint.h>
Should the extra macros be defined or not?
If a header sets a "guard" indicating that it has been included (and that nothing should happen the next time it is included), e.g.,
#ifndef __Header_xxx_guard #define __Header_xxx_guard /* ... guts of header xxx */ #endif
then, how are __STDC_FORMAT_MACROS and __STDC_CONSTANT_MACROS supposed to affect the header when it is included a 2nd time?
The same issue applies to many of the additions to headers done by the various technical reports over the years, e.g.,
#undef __STDC_WANT_DEC_FP__ #include <float.h> #define __STDC_WANT_DEC_FP__ #include <float.h>
Do we need to update 7.1.2 paragraph 4? If so, perhaps something along the lines of a footnote:
Do we need to update the references to __STDC_FORMAT_MACROS and __STDC_CONSTANT_MACROS?
I propose the following changes (the footnote numbers come from N1362):