Author Topic: Run-Time Type Information (RTTI)  (Read 1392 times)

hailstone

  • Local Moderator
  • Battle Machine
  • ********
  • Posts: 1,568
    • View Profile
Run-Time Type Information (RTTI)
« on: 7 October 2009, 08:32:25 »
This is a continuation of the discussion from https://forum.megaglest.org/index.php?topic=4526.msg31780#msg31780

From what I've read you should only use RTTI when the alternative solutions are worse.

From Scott Meyers - http://www.artima.com/intv/const2.html

Advice from Stroustrup in The C++ Language (3rd Ed) [chapter 15.4.5 and 15.5]:
Quote
- Avoid explicit type conversion (casts).
- Use dynamic_cast where class hierarchy navigation is unavoidable.
- Prefer dynamic_cast over typeid.

Many examples of proper use of RTTI arise when some service code is expressed in terms of one class and a user wants to add functionality through derivation.

More info on RTTI - http://www.rcs.hu/Articles/RTTI_Part1.htm

Is it possible to use it only in one library?
Glest Advanced Engine - Admin/Programmer
https://sourceforge.net/projects/glestae/

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Run-Time Type Information (RTTI)
« Reply #1 on: 9 October 2009, 01:55:07 »
Is it possible to use it only in one library?

Use, yes, have enabled in one and not another might be a different story. I've briefly investigated GLGooey's use of RTTI and I believe it can all be eliminated without too much effort.

I suggest that RTTI be outlawed :)
If you need type information for something, maintain it yourself :P
Glest Advanced Engine - Code Monkey

Timeline | Downloads

daniel.santos

  • Guest
Re: Run-Time Type Information (RTTI)
« Reply #2 on: 9 October 2009, 23:29:05 »
OK, I have no major objections.  I'm not experienced with it enough (in C++) to know better.  Personally, it's a pain in the ass to maintain it yourself.  Maybe we can cook up something to make it easier.  Or maybe we can just leave it alone and keep with the way we've been doing it. :)  I guess I'm more concerned about a lot of other things to get too fired up about this right now. :)

silnarm

  • Local Moderator
  • Behemoth
  • ********
  • Posts: 1,373
    • View Profile
Re: Run-Time Type Information (RTTI)
« Reply #3 on: 10 October 2009, 04:14:59 »
Virtual functions should provide the means to solve most problems in a class zoo, if we really do need it then we can turn it on, but I'd prefer to keep it off (and you may want to check that gcc is being told to disable it btw).

It adds overhead (not much admittedly, but we don't need it), and using it is horribly inefficient, from what I can gather, both cl and gcc provide RTTI via strcmp() using the fully qualified class name, with possibly extra name managling... Comparing upwards of 40 bytes to compare types is not cool.

But if it convenient for something, I don't mind that much... but if we do turn it on then we should go through everything and get rid of any unneeded virtual functions.
Glest Advanced Engine - Code Monkey

Timeline | Downloads

daniel.santos

  • Guest
Re: Run-Time Type Information (RTTI)
« Reply #4 on: 10 October 2009, 07:55:04 »
from what I can gather, both cl and gcc provide RTTI via strcmp() using the fully qualified class name....
:oPUKE!!:o

Can we forget I ever brought up RTTI?  I had NO frickin idea!!!!

EDIT: And despite having thought we had it disabled, the -fno-rtti gcc flag was NOT being used!  I've added it to the Jamrules (which I'll check in the next time I commit).
« Last Edit: 10 October 2009, 07:59:43 by daniel.santos »

 

anything