How to positively detect if rtti is enabled or not

Wed Jun 19 17:42:00 GMT 2019

PlatformIO IDE v 2.2.0, Core 3.6.7
VSCode v 1.35.1
Linux Mint v 17.2
gcc v 4:4.8.2-1ubuntu6

I want to display some info about a Class using "typeid", and I know that
requires having build_unflags = -fno-rtti in my platformio.ini, which I
have. But I also want to not REQUIRE that a user enable rtti, because of the
additional memory it uses. So I want to do something like this:

#if <something that positively tells the compiler that rtti is enabled>
virtual const char* getClassName() { return typeid(*this).name(); } 

and use the same #if / #endif around the single line that actually displays
the Class name in the debug message. But I’ve tried all kinds of things for
that , and nothing seems to detect that rtti is enabled, because my method
is never defined and my display code is never called.

I tried: #if _GXX_RTTI, which I found a reference to here on this forum, but
that didn't work - it never evaluated to TRUE, so my method was never
defined and my debug message was never displayed. Ditto for _CPP_RTTI, which
I found on another forum.

Is there something that will tell the preprocessor that rtti is enabled, or
not? Thanks!

Sent from:

More information about the Gcc-help mailing list