__STDC__ and non-conforming ANSI C compilers

Prescott K. Turner turner at sdti.SDTI.COM
Fri Feb 10 00:31:00 AEST 1989


The discussion of __STDC__ has been strongly directed towards the issues of
what implementations should do.  Several articles have mentioned that the
standard could not indicate what a non-conforming implementation should do
with __STDC__.

It's too late now, but the standard could have said more about how
standard-conforming programs use __STDC__.  The effects of this might have
been interesting and useful.

In fact, its failure to say more will probably doom the plan to define
__STDC__ to 2 in future standards.  Consider the following strictly
conforming program:
    #if __STDC__ == 1
    #include <stdio.h>
    int main() {
        printf ("Hello, world.\n");
        return 0;
    }
    #else
          PROGRAM HELLO
          PRINT *, "Hello, world."
          END
    #endif 
Many standard C programs will use __STDC__ with the same #if directive as
above.  If the next standard defines __STDC__ to 2, it will not provide
upward compatibility for these programs.  Many programs would do the "wrong"
thing.

If this had been thought out ahead of time, the present standard might have
required a conforming program to have the same output when run
with a compiler which is otherwise standard-conforming but which has
__STDC__ defined to 2,3,4,5 or ... .

Another reason for the standard to constrain the way a program uses __STDC__
would be for the indirect influence on non-conforming C compilers.  This
could conceivably steer C compilers towards a "correct" way of defining
__STDC__, since most non-conforming compilers would be required by the
user community to support programs which use __STDC__ in whatever way
becomes widespread.  But I don't really have any wording to suggest as
a hypothetical addition to the standard along these lines.
--
Prescott K. Turner, Jr.
Software Development Technologies, Inc.
375 Dutton Rd., Sudbury, MA 01776 USA        (508) 443-5779
UUCP: ...{harvard,mit-eddie}!sdti!turner    Internet: turner at sdti.sdti.com



More information about the Comp.std.c mailing list