c++ - Compile time elimination of virtual tables? -
assuming have hierarchy :
class super { public: virtual void bar(); }; class sub : public super { public: virtual void bar() override; };
is there way me avoid vtables despite using virtual key word? (curiosity) have read compiler optimization eliminates vtables when object known during compile time, i'm not sure, been digging around google while, could't find answers, mean these?
sub sb; sb.bar(); //avoids vtable? super& sr = sb; sr.bar(); //avoids vtable? super* srp = &sb; srp->bar(); //avoids vtable?
one of gcc developers has whole series of blog posts devirtualization. think active on so, there may chance responses.
however, devirtualization deals eliminating virtual dispatch analyzing program flow , possible types. don't think removes virtual table in general, there example in second article virtual gets inlined , can evaluated @ compile time through constant propagation. in case, compiler/linker transformed program not use class @ all, , should not contain object or vtable.
Comments
Post a Comment