__STDC__ defined as zero a problem

Walter Bright bright at Data-IO.COM
Tue Jun 27 05:03:47 AEST 1989


In article <225800190 at uxe.cso.uiuc.edu> mcdonald at uxe.cso.uiuc.edu writes:
>I have noticed several programs posted to the net, or available
>by ftp somewhere that contain lines like
>#if __STDC__
>  /* usually function prototypes */
>#else
>  /* old style declarations */
>#endif
>I find this a bit objectionable, in that this prevents getting the
>benefits of new-style declarations using compilers that support them
>but, correctly, declare __STDC__ to be zero or don't declare it at all.

I agree. There's also the following problem. I suspect that most real-
world compilers are going to have two compilation modes: ANSI C and
Useful C :-). In the ANSI C mode, __STDC__ will be defined, otherwise not.
The ANSI C mode will be used for/by:
	1. people writing compiler reviews for magazines
	2. validating a C compiler against an ANSI C test suite
	3. people who's boss tells them they must
Useful C will be used for/by:
	1. people writing real applications who know what they're doing
The reasons are:
	1. Trigraph support significantly slows down the scanner, which is
	   the most time-consuming part of a compiler. Trigraphs are useless,
	   and so are left out of the Useful C mode.
	2. Compilers for many machines/OSs need extensions in order to
	   efficiently support them. Examples for the PC include near/far/
	   pascal etc.
	3. The ANSI C library is a subset of the library real programmers
	   expect to find declared in the usual .h files. In ANSI C mode,
	   these declarations will be #if'd out.
In other words, ANSI C is a specification for a common subset, but
customers demand more than that for their real work.

So it's ill-advised to expect __STDC__ == PROTOTYPES_SUPPORTED. What I
use is a header file called host.h, which figures out which compiler is
in use and defines PROTOTYPES_SUPPORTED appropriately for that compiler.
For instance, a section of host.h might look like:

	#if __ZTC__ || __TURBOC__	/* if Zortech C or Turbo C	*/
	#define PROTOTYPES_SUPPORTED 1
	#endif

	#ifndef PROTOTYPES_SUPPORTED
	#define PROTOTYPES_SUPPORTED 0
	#endif

Into host.h are collected defines for all the various idiosyncrasies that
cause me trouble.

P.S. I wrote Zortech C/C++.



More information about the Comp.lang.c mailing list