Standard identification of compilers?

Stephen Clamage steve at taumet.com
Wed May 8 01:51:53 AEST 1991


cimshop!davidm at uunet.UU.NET (David S. Masterson) writes:

>Does the proposed standard (C or C++) have a way of identifying whose compiler
>is being used?

No.

>... it seems that every compiler has its
>little quirks that are specific to it.  What I was wondering was if one could:

>	#if (__COMPILER__ == "BC++ v2.02")
>		...
>	#endif

You cannot do exactly this in C at all.  Nowhere in the C language is it
helpful to compare literal strings with ==.  (Even the expression
	"hi" == "hi"
need not result in equality.)

Trying to specify a way to do what you want in the standard opens up
quite a can of worms.

First, the standard deals with the definition of the language, not
specific implementation issues.

Second, how do you specify in a standard how this is going to work?  There
has to be a central clearing house to assign or approve a string for each
compiler.  Who supports such an organization?  Who runs it?  Who ensures
its continued existence when the current operators get bored or die?  Who
enforces compliance, and how?  There are both volunteer and government-
run institutions which perform comparable services, but no language
standard could possibly address these issues.

(We have a different situation with Ada, which is a creation of the
US Government.  It owns the "Ada" name and sets all the rules.  If you
don't follow the rules, you can't call your product an Ada compiler.)

Third, the standard could not enumerate all possible C compilers,
since some would come into existence between approval and publication,
let alone after publication.  So you would have to find out on a compiler-
by-compiler basis what the special strings were and modify your program
for each new compiler.  This is just what you have to do now with no
intervention by the standard.

Finally, your proposal doesn't help with compilers which do not follow the
ANSI standard for whatever reason.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.std.c mailing list