Identifying GCC in the preprocessor
Segher Boessenkool
segher@kernel.crashing.org
Mon Nov 10 16:06:30 GMT 2025
Hi!
On Thu, Nov 06, 2025 at 03:56:19PM -0600, Ian Pilcher via Gcc-help wrote:
> How can I identify GCC (and not some other rando compiler that has
> decided to define __GNUC__) during compilation, so that I can issue a
> warning?
As the manual describes, the macro __GNUC__ should be the major version,
and __GNUC_MINOR__ the minor version, and __GNUC_PATCH_LEVEL__ the
patchlevel of the GCC version in use. GCC always defines all three,
perhaps you can use that?
Some other compilers indeed do a great disservice to the world and lie
in the macros they themselves predefine, pretending to be GCC. And
these symbols start with two underscores, so are reserved for the
implementation, so they have absolutely no excuse for this :-(
> This seems to be a lot harder than it should be.
Yes. But we can do almost nothing about others' misbehaviour.
Segher
More information about the Gcc-help
mailing list