For the specific example of distinguishing a C++ compiler from a C compiler, the sensible choice is the macro __cplusplus
which is defined by the C++ standard to exist, and due to side effects of the reserved name rules a clause that says so in standard C, will never be predefined by the C compiler.
Every compiler has a collection of predefined macros that are occasionally useful for distinguishing among compilation hosts and target platforms. One large repository of such macros is the Predef Project where they are collecting reports on as many combinations of compiler, host, and target as they can.
Edit: Clarifying the reserved nature of __cplusplus
in C: The C standard has always reserved identifiers that begin with two underscores or one underscore followed by a capital letter. For instance, C99 in section 7.1.3 says
"All identifiers that begin with an underscore and either an uppercase letter or another underscore are always reserved for any use.",
and several other clauses carry a footnote that reads in part
"Implementation-defined keywords shall have the form of an identifier reserved for any use as described in 7.1.3."
So, without any further direction from the standard, in a compliant implementation of a C compiler the name __cplusplus
is reserved for any use. That name was chosen by the implementors of C++ specifically because it was reserved in C, has a clear meaning, and was not known to have been defined by any C implementation.
However, by C99 the standards committee had decided to make sure that no C implementation damaged the obvious utility of a macro that could be used to distinguish a C compilation from a C++ compilation. In C99 section 6.10.8 they write:
"The implementation shall not predefine the macro _ _cplusplus, nor shall it define it
in any standard header."
Its hard to get more clear than that.