Is there a g++ equivalent to Visual Studio's __declspec(novtable)?
Asked Answered
P

1

16

Is there a g++ equivalent to Visual Studio's __declspec(novtable) argument?

Basically, in a pure virtual base class the __declspec(novtable) argument can be used to suppress the creation of a vtable for the base class as well as vtable initialization/deinitialization code in the contstructor/destructor respectively. E.g.,

class __declspec(novtable) PureVirtualBaseClass
{
    public: 
       PureVirtualBaseClass(){}
       virtual ~PureVirtualBaseClass() = 0;
};

See Paul DiLascia's article for more info. Also see my related question.

Pydna answered 24/11, 2009 at 4:20 Comment(4)
Just curious: It seems to me that discarding the vtable for PureVirtualBaseClass is a microoptimization, and generally a very small one at that. What's the reason for wanting to do this?Sabol
Read DiLascia's article, he covers the reasons for wanting to do this better than I can.Pydna
Also, found this msdn.microsoft.com/en-us/library/k13k85ky.aspx today on MSDN where they suggest there can be a significant reduction in program size using __declspec(novtable).Pydna
Wouldn't whole program optimization let the compiler remove the vtables for any classes that aren't instantiated anyway?Aftmost
M
9

I don't think there is one -- if there was, it would be listed under the type attributes page of the GCC manual. GCC uses type attributes to add extra annotations to types (such as alignment and padding), but there is no type attribute equivalent to __declspc(novtable) listed there.

I also don't see any compiler flag in the command line options relating to this optimization.

Miranda answered 24/11, 2009 at 4:53 Comment(3)
It's been a while. Does this answer still apply?Singlebreasted
I believe nowadays gcc has the -fdevirtualize switch which is in the -O2 optimizationChristensen
@Christensen No, according to the documentation on -fdevirtualize gcc.gnu.org/onlinedocs/gcc/… , that is a completely different optimization.Miranda

© 2022 - 2024 — McMap. All rights reserved.