Search code examples
clanguage-lawyerc11standards-compliance

Why isn't an IEC 60559 conformant implementation required to define __STDC_IEC_559__ (to 1)?


The C (C99+) standard requires (though implicitly) a conforming implementation to define __STDC__ to 1.

However, the C standard does not require an IEC 60559 conformant implementation to define __STDC_IEC_559__ (to 1).

Consequences:

#if __STDC__ != 1
/* non-conforming implementation */
#endif

#if __STDC_IEC_559__ != 1
/* may be IEC 60559 conformant implementation */
#endif

Here we see that there is no consistency in the semantics of these macros. Any ideas why? Is it a possible defect?

Why the C standard does not require an IEC 60559 conformant implementation to define __STDC_IEC_559__ (to 1)?


Solution

  • It's in the implementation's own best interest to define it. C17 6.10.8.3:

    __STDC_IEC_559__ The integer constant 1, intended to indicate conformance to the specifications in annex F (IEC 60559 floating-point arithmetic).

    While it technically would be possible for the compiler not to define it, it doesn't make any sense not to, in case it does conform to IEC 60559. It's a quality of implementation stamp, just like __STDC__ or __STDC_VERSION__.

    Notably, this constant has only been around since C99, so it would be possible that C90 implementations use IEC 60559 without defining the macro constant.