0

Context: C compilers deliberately do not support some features while being conforming implementations. Is it ok?

Some examples. All of the compilers down below are conforming implementations (__STDC__ is defined to 1). However:

  • gcc does not support #pragma STDC FENV_ACCESS and issues warning: ignoring ‘#pragma STDC FENV_ACCESS’ [-Wunknown-pragmas]. However, fenv.h is a standard header, and support of #pragma STDC FENV_ACCESS ON is required by the standard, because ON is one of the choices in on-off-switch: ON OFF DEFAULT.

  • msvc does not support #pragma STDC FP_CONTRACT and rather supports its own version #pragma fp_contract ( { on | off } ). However, the standard version is #pragma STDC FP_CONTRACT { ON | OFF | DEFAULT }.

  • gcc on Cygwin: sscanf doesn't handle hexadecimal floating-point input. And libc is a part of the standard.

Question: is it allowed for an implementation to deliberately provide a limited functionality (or its own version of such functionality) and still be conforming implementation at the same time?

Reason of the question: better understanding of the definition of conforming implementation and the state of affairs around existing conforming implementations.

Note: here the area of interest is conforming hosted implementation only. However, the question is applicable for conforming freestanding implementation as well.

UPD. Again: __STDC__ is defined to 1 means maybe conforming implementation rather than conforming implementation. Any discrepancy with the standard automatically makes such implementation be "nonconforming implementation that defines __STDC__ to 1".

pmor
  • 5,392
  • 4
  • 17
  • 36
  • 2
    Re “All of the compilers down below are conforming implementations (`__STDC__` is defined to 1)”: As you have been told previously, the latter does not imply the former. The C standard requires conforming implementations to define `__STDC__` to `1`. It has no jurisdiction over non-conforming implementations can cannot prohibit them from defining `__STDC__` to 1. – Eric Postpischil Jul 16 '21 at 11:41
  • 1
    It is a fundamental principle that to conform to a specification, an implementation must conform to the rules of the specification. If a standard has a rule that an implementation does X, and an implementation does not do X, then it is not conforming. It is plain that, if the facts stated in this question are true, the implementations are not conforming. So what is the point of asking this question? – Eric Postpischil Jul 16 '21 at 11:43
  • @EricPostpischil Right, thanks: they are _maybe_ conforming implementations. However, for example, msvc claims that [_we are officially supporting the latest ISO C language standards_](https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/). Does _support of the latest ISO C language standards_ mean _conforming implementation_? – pmor Jul 16 '21 at 11:52
  • 6
    If a standard has a rule that an implementation does X, and an implementation does not do X, then it is not conforming. – Eric Postpischil Jul 16 '21 at 11:52
  • @EricPostpischil And _GCC aims towards being usable as a conforming freestanding implementation, or as the compiler for a [conforming hosted implementation](https://gcc.gnu.org/onlinedocs/gcc/Standards.html)_. – pmor Jul 16 '21 at 11:56
  • 1
    Aiming toward conformance does not guarantee conformance. **This is plain and simple: If a standard has a rule that an implementation does X, and an implementation does not do X, then it is not conforming.** – Eric Postpischil Jul 16 '21 at 11:57
  • 1
    @pmor If GCC is aiming, it missed. – Andrew Henle Jul 16 '21 at 13:16
  • @EricPostpischil: That is generally true, but a Standard may include a specific definition of conformance which waives general requirements in some cases. Conforming C Implementations are not be required to correctly process Strictly Conforming C Programs that nest function calls 5,000,000 levels deep, nor even 3 deep for that matter, and the definitions of Strictly Conforming C Program and Conforming C Program regard constraints as only applicable to the latter. – supercat Jul 20 '21 at 17:34
  • @pmor: Given that the Standard makes no attempt to specify everything (or even much of *anything*) a freestanding implementation must do to be useful for any particular purpose (or *any non-trivial purpose whatsoever*), a compiler writer who interprets the Standard's failure to mandate support for a construct as an invitation to regard any code that would require it as "broken" isn't trying to make a quality freestanding implementation. – supercat Jul 20 '21 at 17:37
  • @EricPostpischil Observation about clang: since clang [does not document implementation-defined behavior](https://bugs.llvm.org/show_bug.cgi?id=11272), it makes it non-conforming implementation, which defines `__STDC__` to 1. – pmor Jul 28 '21 at 13:31

1 Answers1

5

If a standard has a rule that an implementation does X, and an implementation does not do X, then it is not conforming.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
  • According to the Standard, all that is necessary for an implementation to be conforming is that there exist some program (which may be contrived and useless) which nominally exercises the translation limits given in the Standard, and that the implementation processes in conforming fashion. Provided an implementation does that, it may impose arbitrary translation limits of its own, such as requiring that a program not contain more than 10,000 characters total worth of identifier names in scope at once, or requiring that it not contain the letter `r` more than twice, and may... – supercat Jul 20 '21 at 17:29
  • ...behave in arbitrary fashion if any of its translation limits are exceeded. – supercat Jul 20 '21 at 17:29