Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!cimshop!davidm From: cimshop!davidm@uunet.UU.NET (David S. Masterson) Newsgroups: comp.std.c++ Subject: Re: Standard identification of compilers? Message-ID: Date: 8 May 91 18:22:21 GMT References: <714@taumet.com> Sender: davidm@cimshop.UUCP Followup-To: comp.std.c++ Distribution: comp Organization: Consilium Inc., Mountain View, California Lines: 86 In-reply-to: steve@taumet.com's message of 7 May 91 15:51:53 GMT >>>>> On 7 May 91 15:51:53 GMT, steve@taumet.com (Stephen Clamage) said: Stephen> cimshop!davidm@uunet.UU.NET (David S. Masterson) writes: David> Does the proposed standard (C or C++) have a way of identifying whose David> compiler is being used? Stephen> No. David> ... it seems that every compiler has its little quirks that are David> specific to it. What I was wondering was if one could: David> #if (__COMPILER__ == "BC++ v2.02") David> ... David> #endif Stephen> You cannot do exactly this in C at all. Nowhere in the C language is Stephen> it helpful to compare literal strings with ==. (Even the expression Stephen> "hi" == "hi" need not result in equality.) I guess I wasn't clear here. I know that what I put above is not legal, it was just an example/idea of what I was looking for. Stephen> Trying to specify a way to do what you want in the standard opens up Stephen> quite a can of worms. Stephen> First, the standard deals with the definition of the language, not Stephen> specific implementation issues. I'm not suggesting that it deal with implementation issues, just allow the user to determine what the specific implementation is that he is dealing with (*iff he needs to*). Stephen> Second, how do you specify in a standard how this is going to work? Stephen> There has to be a central clearing house to assign or approve a Stephen> string for each compiler. Who supports such an organization? Who Stephen> runs it? Who ensures its continued existence when the current Stephen> operators get bored or die? Who enforces compliance, and how? There Stephen> are both volunteer and government run institutions which perform Stephen> comparable services, but no language standard could possibly address Stephen> these issues. The standard already has a number of "implementation defined" things in it. There need not be a clearing house to assign strings, it could be left to the individual vendors *provided the standard gives them enough latitude*. For instance, if differentiating between compilers is done on the basis of one number, then its very likely that vendors are going to conflict. However, if there is a number for the vendor's name (defined by some modulo arithmetic) plus a couple other constants (for compiler and version number), then it becomes extremely unlikely that they will conflict. And even if there are conflicts, it only affects the relatively few people that use both of the conflicting compilers. Stephen> Third, the standard could not enumerate all possible C compilers, Stephen> since some would come into existence between approval and Stephen> publication, let alone after publication. So you would have to find Stephen> out on a compiler by compiler basis what the special strings were Stephen> and modify your program for each new compiler. This is just what you Stephen> have to do now with no intervention by the standard. Hmmm. This is your best point. However, given the need for differentiating between compilers (see below), having a single (set of) constants to query for compiler information cuts down on potential conflicts between the names of those constants and what someone may choose for their own constant name (we were using a VAX constant in our code before we realized VAXC is defined by the compiler -- missed it by one letter). It also cuts down on the misinterpretations that occur by new users of a compiler ("hmmm, what constants does *this* compiler define?"). Stephen> Finally, your proposal doesn't help with compilers which do not Stephen> follow the ANSI standard for whatever reason. Its not meant to help with the compilers, its simply to allow users to gear their code to quirks in (possibly braindead) compilers. In the real world, users can't always abandon a compiler or a vendor when something they really need doesn't work as expected with a particular compiler. This may especially be a problem with an evolving standard like C++ where various vendors may call themselves ANSI-compliant (and so define __cplusplus__) and either not truly be compliant or have the standard change on them (as in 1.2 to 2.x). -- ==================================================================== David Masterson Consilium, Inc. (415) 691-6311 640 Clyde Ct. uunet!cimshop!davidm Mtn. View, CA 94043 ==================================================================== "If someone thinks they know what I said, then I didn't say it!"