This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: C++ attributes ?


> If you know what com_interface is about, why don't you enlighten me ?

Adding to Jason's explanation: Microsoft COM is the ABI used in
Microsoft OLE2 and Microsoft ActiveX. A COM interface is a set of
operation signatures, which are numbered in the order in which they
are declared (starting from zero). A COM object has, at offset 0, a
pointer to a dispatch table.

COM interfaces can be implemented in C and C++; for C++, Microsoft
Visual C++ arranges the layout of the vtables so that C++ objects act
as if they implement a COM interface.

The COM ABI does not support the full set of C++ features (no RTTI, no
virtual dtors). The native g++ ABI supports all these things, but in a
different way.

The com_interface __attribute__ tells g++ that the object should
support the COM ABI.

Please note that I haven't actually looked at the implementation, but
I would expect it to do the following things:
- it checks whether a com_interface class is used with the right
  restrictions (no virtual dtors, not used in dynamic_cast and typeid,
  vtbl is at offset zero - i.e. the primary base must also be com_interface)
- it checks whether all operations in the com_interface class are
  __stdcall__ (is that actually a requirement?)
- it builds the vtbl according to the COM convention, no matter what
  the ABI default is
- classes which use a com_interface as a primary base are also
  com_interface (apparently implicitly)

With that, one can write

struct __attribute__((com_interface)) IUnknown{
  virtual HRESULT QueryInterface(REFIID riid, void **ppvObject)=0;
  virtual ULONG AddRef()=0;
  virtual ULONG Release()=0;
};

and that's enough for a complete COM hierarchy.

Hope this helps,
Martin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]