-4

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)?

Nate Eldredge
  • 48,811
  • 6
  • 54
  • 82
pmor
  • 5,392
  • 4
  • 17
  • 36
  • Possibly for backwards compatibility with implementations conforming to an earlier version of the standard. – Ian Abbott May 06 '22 at 15:18

1 Answers1

1

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.

Lundin
  • 195,001
  • 40
  • 254
  • 396
  • Re: "it doesn't make any sense not to": indeed, sounds rational. Extra: Clang defines `__STDC_IEC_559__` to 1 via `#include `, which violates C11, 6.10.8/2. While GCC _preincludes_ ``. It seems that Clang needs to be fixed. – pmor May 09 '22 at 12:55