help-gplusplus
[Top][All Lists]
Advanced

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

Omit vtbl for "interfaces"


From: Scott Meyers
Subject: Omit vtbl for "interfaces"
Date: Tue, 01 May 2007 22:48:32 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070326 Thunderbird/2.0.0.0 Mnenhy/0.7.5.0

Consider this class:

class Widget {
public:
  virtual void mf1() = 0;
  virtual void mf2() const = 0;
  virtual int someVal() = 0;
  virtual ~Widget() {}
};

The class is abstract and has no meaningful virtual function implementations. There is no reason for this class to have a vtbl nor for its (implicit) constructors or its destructor to adjust the vptr, because there is no way to use them that will not lead to undefined behavior. Some other compilers either omit the vtpr/vtbl code and data for such classes or offer programmers a way to suppress it (e.g., Microsoft's __declspec(novtable)). I can't find any information that suggests that gcc supports such an optimization, which is especially of interest in the embedded community. Does anybody know definitively whether gcc does or does not offer this optimization?

Thanks,

Scott


reply via email to

[Prev in Thread] Current Thread [Next in Thread]