Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!apple!bloom-beacon!mit-eddie!uw-beaver!uw-entropy!dataio!bright From: bright@Data-IO.COM (Walter Bright) Newsgroups: comp.lang.c Subject: Re: __STDC__ defined as zero a problem Message-ID: <2029@dataio.Data-IO.COM> Date: 26 Jun 89 19:03:47 GMT References: <225800190@uxe.cso.uiuc.edu> Reply-To: bright@dataio.Data-IO.COM (Walter Bright) Organization: Data I/O Corporation; Redmond, WA Lines: 51 In article <225800190@uxe.cso.uiuc.edu> mcdonald@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++.