0

Why it (seems that it) is a general practice for C compiler vendors to not provide to the end users an additional conformance documentation about implementation-defined behavior regarding «other forms of constant expressions» (C11, 6.6.10)?

C11, 6.6.10:

An implementation may accept other forms of constant expressions.

This fact leads to the following reactions / feedback (taken from different sources):

SO user M.M:

The compiler vendor should publish conformance documentation listing which expressions it accepts as constants, although I couldn't find that documentation for MSVC. (leave a comment if you can!)

Source: https://stackoverflow.com/a/62161678/9881330

SO user Keith Thompson:

Admittedly the standard doesn't seem to require such documentation (which I find a little surprising).

Source: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66618 (2015-07-01 00:48:48 UTC)

Since the 6.6.10 is related to the implementation-defined behavior, and since «each implementation shall include documentation describing its characteristics and behavior» (C++ standard, section 1.9), why it is not a general practice in case of 6.6.10? If someone here represents any (industrial) C compiler vendor then please provide the reason / comment the situation.

P.S. The origin of the question is the possible portability issues related to the «other forms of constant expressions». It will be much time-saving if the end users know exactly which «other forms of constant expressions» are «accepted by the implementation» before writing the code (and not after, being surprised by the portability issues).

UPD. Note on «When making use of implementation-defined behavior, I would assume portability issues until proven otherwise». If a software product is planned to be portable between N compilers and all the N compilers support the same IB-related language feature, which is useful while writing the code, but considered implementation-defined behavior, then why not use it? The only question is that we need to know in advance that this IB-related language feature is supported between all the N compilers. (Yes, we can empirically / experimentally find it, but in case of many IB-related language features it will be probably time-consuming. It is better to have an official statement from the compiler vendor that this IB-related language feature is supported / not supported.)

UPD: About "the standard doesn't seem to require such documentation": C11, 4. Conformance:

An implementation shall be accompanied by a document that defines all implementation-defined and locale-specific characteristics and all extensions.

UPD: I see the current state of affairs as follows: the C standard permits to "accept other forms of constant expressions". And gcc, clang, and icc do support other forms of constant expressions (demo). However, the C standard is silent about whether such other forms of constant expressions are required to be accepted consistently across multiple usages (see the demo).

pmor
  • 5,392
  • 4
  • 17
  • 36
  • When making use of implementation-defined behavior, I would assume portability issues until proven otherwise. – Christian Gibbons Jul 03 '20 at 19:06
  • Since MSVC compilers do not conform to C standards, you cannot expect them to conform to that clause either. But MS does provide extensive documentation. – Weather Vane Jul 03 '20 at 19:10
  • Since you seem to be quoting answers or comments on Stack Overflow, [edit] the question to include links to those sources. – 1201ProgramAlarm Jul 03 '20 at 19:10
  • Someone apparently found an impl. defined constant expression in clang here: https://stackoverflow.com/questions/30158413/gcc-doesnt-support-simple-integer-constant-expression/30158502. Look in the clang manual, does it mention it? – Lundin Jul 03 '20 at 19:24
  • One possible explanation is obvious: the standards committee aren't your customers, and actual customers don't care about having such a document. So why spend time and money writing it if it won't improve sales / adoption of your compiler? – Nate Eldredge Jul 03 '20 at 21:25

0 Answers0