Search code examples
clanguage-lawyerlimitc11diagnostics

Should implementations issue a diagnostic if the internal fixed / non-fixed translation limits are exceeded?


Context: C11:

Implementations should avoid imposing fixed translation limits whenever possible.

Consider a case: the internal fixed / non-fixed translation limits are exceeded, leading to silent generation of the wrong code.

It seems reasonable to issue a diagnostic if the internal fixed / non-fixed translation limits are exceeded. Does anyone know if the implementations already do that?


Solution

  • Consider a case: the internal fixed / non-fixed translation limits are exceeded, leading to silent generation of the wrong code.

    The language specification says very little about what may happen if translation limits are exceeded. In fact, it hasn't anything at all to say about translation limits beyond paragraph 5.2.4.1/1 and footnote 18, which you have already been reading.

    Applying a language-lawyer reading to the specifications, we can observe that they neither explicitly specify that the behavior of a program that exceeds an implementation's translation limits is undefined, nor restrict their specifications of implementation and program behavior to programs that conform to all translation limits. It follows, then, that program behavior does not fail to be defined on account of the program exceeding translation limits. As a result, your hypothetical case does not arise from a combination of a conforming implementation and a conforming program.

    What the specifications leave unsaid is that implementation and program behavior are contingent on the implementation accepting the program in the first place. Conforming implementations are not required to accept all conforming programs, nor even all strictly conforming programs. The avenue open to conforming implementations when faced with a program that exceeds its translation capabilities is to reject the program. If an implementation accepts and translates a given program, then implementation conformance requires that the program behave as described by the language specification.

    It seems reasonable to issue a diagnostic if the internal fixed / non-fixed translation limits are exceeded. Does anyone know if the implementations already do that?

    Implementations that reject a program at translation time, whether because translation limits are exceeded or for some other reason, generally do provide appropriate diagnostics. Of course, no one here can promise that every implementation provides such a diagnostic in every case.

    Overall, I think I have already answered your main concern: except inasmuch as C implementations could have bugs in this area, you do not have to be concerned about undefined program behavior arising from exceeding translation limits.