Re: How to positively detect if rtti is enabled or not

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 19 Jun 2019, ba58smith wrote:

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(); }
#endif

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!

You got the number of underscores wrong.

Create an empty file empty.cc, then

$ g++ -E -dM e.cc > 1
$ g++ -E -dM e.cc -fno-rtti > 2
$ diff 1 2
108d107
< #define __GXX_RTTI 1
202d200
< #define __cpp_rtti 199711


--
Marc Glisse



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux