0

Is there any C compiler(s) which defines both __STDC__ and __STDC_IEC_559__ to 1?

If so, then which one(s)?

Reason of the question: as far as I can test (April 2021), none of the latest versions of popular C compilers (gcc, clang, msvc) define both __STDC__ and __STDC_IEC_559__ to 1. Hence, these compilers may generate executable files, which produce non-IEEE 754 conformant results. However, there is a demand on such C compilers, which actually provide a guarantee / confidence that generated executable files produce IEEE 754 conformant results (under strict floating-point model option).

pmor
  • 5,392
  • 4
  • 17
  • 36
  • 1
    Why do you wonder? Is there an underlying problem you need to solve, or just plain curiosity? If it's curiosity then please tell us, otherwise please ask us directly about the problem. – Some programmer dude Mar 31 '21 at 22:41
  • 3
    @pmor You may need to set appropriate compiler switches for maximum IEEE-754 compliance. I tried the latest release versions of gcc, icc, and clang for x86-64 at [Compiler Explorer](https://godbolt.org) and with `-frounding-math -fsignaling-nans` all three report both `__STDC__` and `__STDC_IEC_559__` as `1`. – njuffa Apr 01 '21 at 02:56
  • @user3386109 Strictly speaking, C11 (or any edition of the C standard) requires *conforming* compilers to define `__STDC__` as `1`. (Non-conforming compilers can do anything they like.) – Keith Thompson Apr 01 '21 at 04:19
  • @pmor No matter what command line switches I try, MSVC 2019 doesn't seem to define either `__STDC__` or `__STDC_IEC_559__`. It tried `/fp:strict` in conjunction with all available C and C++ `/std:` switch settings. – njuffa Apr 01 '21 at 06:09
  • @njuffa `__STDC_IEC_559__ as 1`: Many thanks for the confirmation! It turns out that `__STDC_IEC_559__` value (if defined) depends of the host OS. For example, both gcc 10.2.0 (with `-frounding-math -fsignaling-nans`) and clang 11.0.1 (with `-ffp-model=strict`) running on Windows 10 (version 2004) do not define `__STDC_IEC_559__ to 1`. – pmor Apr 01 '21 at 15:26
  • @KeithThompson Thanks for noting this aspect. It was mentioned in comments for [this](https://stackoverflow.com/q/65744941/1778275) question as well. – pmor Apr 01 '21 at 15:34
  • @njuffa FYI: `cl.exe` version `19.28.29913` under `/std:c11 /Za` does define `__STDC__` to `1`. – pmor May 24 '21 at 17:37

1 Answers1

0

Yes. It turned out that in gcc and clang definition of __STDC_IEC_559__ depends on the host OS. In case of Windows: __STDC_IEC_559__ is 0. In case of Linux: __STDC_IEC_559__ is 1.

Here are the options to get both __STDC__ and __STDC_IEC_559__ defined to 1:

clang -std=c11 -ffp-model=strict
gcc -std=c11 -frounding-math -fsignaling-nans

UPD20211229: Intel C compiler defines both __STDC__ and __STDC_IEC_559__ to 1:

icc -std=c11 -fp-model=strict
pmor
  • 5,392
  • 4
  • 17
  • 36