Detect compiler with #ifdef
Asked Answered
F

3

8

I'm trying to build a small code that works across multiple platforms and compilers. I use assertions, most of which can be turned off, but when compiling with PGI's pgicpp using -mp for OpenMP support, it automatically uses the --no_exceptions option: everywhere in my code with a "throw" statement generates a fatal compiler error. ("support for exception handling is disabled")

Is there a defined macro I can test to hide the throw statements on PGI? I usually work with gcc, which has GCC_VERSION and the like. I can't find any documentation describing these macros in PGI.

Feldstein answered 5/8, 2009 at 13:58 Comment(1)
clang #2658961 | VC #15128022Sisco
T
12

Take a look at the Pre-defined C/C++ Compiler Macros project on Sourceforge.

PGI's compiler has a __PGI macro.

Also, take a look at libnuwen's compiler.hh header for a decent way to 'normalize' compiler versioning macros.

Tommietommy answered 5/8, 2009 at 14:58 Comment(1)
Second link is dead :(Jorin
D
4

You could try this to see what macros are predefined by the compiler:

pgcc -dM

Maybe that will reveal a suitable macro you can use.

Dermatoglyphics answered 5/8, 2009 at 14:6 Comment(2)
Indeed. The output of that is shown at pgroup.com/support/tprs_70.htm, and there's PGI (mentioned above), and __PGIC, PGIC_MINOR, and PGIC_PATCHLEVEL, which give the major, minor, and patchlevel parts of the compiler version number.Towill
And there's the joy of the parser taking double underscores and doing entertaining things with them. 'PGI' is prefixed with double underscores; the other three are both prefixed and suffixed with them.Towill
M
0

Have you looked at the boost headers? Supposing they support PGI, they will have found a way to detect it. You could use that. I would start to search somewhere in boost/config.

Meganmeganthropus answered 5/8, 2009 at 14:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.