-fno-rtti & dynamic_cast?

Status
Not open for further replies.

jim lee

Well-known member
Ok, can someone explain what the -fno-rtti compiler directives are? And, why they think "dynamic_cast" is an error? I see the teensy uses these and the UNO doesn't. I've read -here- that the UNO allows sloppy compiling but this kinda' has me stuck.

Code:
void change2ndFx(boolean setClear) {

  drawObj*    node;
  calcButton* trace;
  
  node = viewList.theList;
  while(node) {
    trace = dynamic_cast<calcButton*>(node);
    if (trace) trace->setSecond(setClear);
    node = (drawObj*)node->next;
  }
}

This is the actual routine. Everything in the list are drawObj pointers. Some can be up-cast to the derived calcButton pointers. I can show more code. But where does it stop? There is so much of it.

OK, been looking things up.

RTTI is short for Run-time Type Identification. RTTI is to provide a standard way for a program to determine the type of object during runtime.

Why is RTTI turned off? What am I missing here?

Thanks!

-jim lee
 
Last edited:
So I went into boards.txt, found the block of info. for the Teensy 3.1/3.2 and removed the -fno-rtti bit. Restarted everything and there was about a hundred what looked like linker errors. So, I put it back.

-jim lee
 
I have not use Run-time Type Identification for a long time and never on a small processor, as it does generate a LOT of additional code and tables, which is why I assume it was turned off here. My guess is, that if you were to really want to use it, you need to change options for both the compiler and the linker
 
Ok, thanks. As I thought about the huge list of errors I got, I'd started to suspect that was the issue. I also posted the same question at the Arduino forum 'cause I noticed the UNO is set the same way. The answer I got there was the same. Huge memory loss if used.

So, after sulking for a bit, I rewrote the code to work a different way and everything's fine. At least I know now.

Thanks again for the reply, I really appreciate it.

-jim lee
 
RTTI and exceptions are C++ features that add a lot of bloat to compiled programs. They're turned off for Teensy and most other microcontrollers.
 
Hello again everyone, back on processors again from doing other things for a long time.

I have a question.

baseClass;

derivedClass;

I was under the impression that if I called the destructor on a base class, that it would cause the destructor of the derivedClass to be called. I looked this up (on the net) and it seems from that, that if the destructors are virtual, this should be the case. Now, would turning off the dynamic_cast (RTTI) deal also turn off the ability for a destructor to find and call its derived class's destructor?

Thanks!

-jim lee
 
Ok, never mind. I wrote a bunch of test cases and it seems to work great. Was all worried for nothing I guess.

-jim lee
 
Status
Not open for further replies.
Back
Top