__STDC__ and non-conforming ANSI C compilers

Doug Gwyn gwyn at smoke.BRL.MIL
Sat Jan 28 15:02:16 AEST 1989


In article <2525 at pegasus.ATT.COM> hansen at pegasus.ATT.COM (Tony L. Hansen) writes:
>    2)	Should it #define __STDC__ to be 1 by default?
>	First off, can it?

Of course it CAN; a nonconforming implementation can do anything it wants.
The question is, if it did, would that cause problems for applications?
The answer to that is definitely YES, it would.

>	Because it declares the extra functions, does that prevent it
>	from being a "fully conforming" ANSI C compiler?

Yes, it does.

If the visibility of the extra functions in the standard headers is
controlled by #ifdef _POSIX_SOURCE, on the other hand, then that is
not non-conforming, provided that _POSIX_SOURCE is not predefined by
the implementation.

>	Perhaps it SHOULD #define __STDC__ as 1 for both modes.

No, it shouldn't -- it definitely CAN matter to a strictly-conforming C
application, and if __STDC__ were 1 in such a non-conforming environment,
the application would have no way to determine that it is going to have a
problem.  I can accept __STDC__==0 for this, if we get near-universal
agreement on it, but not __STDC__==1 in ANY non-conforming environment,
no matter how "small" you consider the deviation to be.

For __STDC__==1, I consider that it suffices for practical purposes to
consider an implementation conforming if no strictly-conforming C program
can detect the difference.  Thus it wouldn't bother me for __STDC__ to be
set to 1 in an environment that provides upward-compatible extensions to
ANSI C.  Extra identifiers usurped from the application's name space do
not qualify as upward-compatible extensions.

>    3)	Is the SVr4 C compiler useful with this scheme?
>	My feeling is yes. I can use "#ifdef __STDC__" to fully differentiate
>	within my code between the old K&R C and new ANSI C syntaxes.

But syntax is not the only difference between those two C environments.

>By the way, I also reject the opinion that using -D when invoking an ANSI C
>compiler:
>	ansicc -Dxyz
>should suddenly cause __STDC__ to be undefined. (Sorry Doug, I think you're
>wrong here.)

I've since acknowledged that so long as the predefinition is being done
explicitly by the compiler user, not automatically by the compiler, it
would be most usefully considered as shorthand for editing all the
sources to temporarily "#define xyz 1".  Therefore that would not be
a "predefined" identifier in the ANSI C sense and would not require that
__STDC__ be changed from its normal value (1, 0, not defined, whatever).

On the other hand, if the compiler automatically predefines macros in
the application's reserved name space, or if it automatically predefines
macros in its own name space that cause other identifiers in the
application's name space to be usurped (e.g. _POSIX_SOURCE), then I
definitely want __STDC__ to NOT be set to 1.



More information about the Comp.std.c mailing list