clanguage-lawyerportabilityc11

Why doesn't the use of strictly conforming programs and conforming implementations ensure absolute portability?


C11, 4. Conformance, footnote 5 (emphasis added):

Strictly conforming programs are intended to be maximally portable among conforming implementations.

Why does the combination of strictly conforming programs && conforming implementations lead to a gradation of portability (i.e. maximally)?

In other words, why doesn't the combination of strictly conforming programs && conforming implementations lead to absolute portability?

What are the obstacles / challenges to ensure absolute portability?


Solution

  • The C standard covers both hosted and freestanding implementations. There is (and could be) no "absolute portability" between the two. For hosted implementations in particular, strict compliance guarantees portability, per the same Conformance section (C11 4.5-6):

    1. A strictly conforming program shall use only those features of the language and library specified in this International Standard. It shall not produce output dependent on any unspecified, undefined, or implementation-defined behavior, and shall not exceed any minimum implementation limit.

    2. The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. A conforming freestanding implementation shall accept any strictly conforming program in which the use of the features specified in the library clause (clause 7) is confined to [...]


    [ EDIT ] As pointed out by @Nate Eldredge in comments below, the statement that a conforming (hosted) implementation "shall accept any strictly conforming program" does not amount to a guarantee that it will "be able to translate and execute" the same strictly conforming program.

    This is because the 5.2.4 Environmental Limits section lists a number of minimum limits, but only requires that "the implementation shall be able to translate and execute at least one program that contains at least one instance of every one of the following limits".

    In other words, even if a strictly conforming program follows 4.5 and does "not exceed any minimum implementation limit", there is still no guarantee by the letter of the C law that the implementation will be able to succesfully compile and run it. As @Jerry Coffin put it in this answer to a related question: "a "hello world" program isn't strictly conforming".

    Or, as Derek M. Jones commented in The New C Standard:

    The topic of a perverse implementation, one that can successfully translate a single program containing all of these limits but no other program, crops up from time to time. Although of theoretical interest, this discussion is of little practical interest, because writing a translator that only handled a single program would probably require more effort than writing one that handled programs in general.