[comp.std.c] Standard identification of compilers?

davidm@uunet.UU.NET (David S. Masterson) (05/06/91)

Does the proposed standard (C or C++) have a way of identifying whose compiler
is being used?  I know its bad form to build code specific to a compiler when
that compiler conforms to a standard, but 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

That way, *if you have to*, you could gear your code to a quirk.  Is there a
standard for this?  If not, why not?
--
====================================================================
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!"

steve@taumet.com (Stephen Clamage) (05/07/91)

cimshop!davidm@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@taumet.com

joe@proto.com (Joe Huffman) (05/07/91)

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

>Does the proposed standard (C or C++) have a way of identifying whose compiler
>is being used?  I know its bad form to build code specific to a compiler when
>that compiler conforms to a standard, but 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

I think your suggestion needs some modification... The test shown will generate
a syntax error no matter what __COMPILER__ is defined to (an integer constant
expression is expected).

You might just compile a list of what the different vendors use for 
identification.  Zortech uses __ZTC__ which expands to the version number in
hex.  For example: version 2.18 would have __ZTC__ equal to 0x218.
-- 
joe@proto.com