This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: C++ attributes ?
- To: Marc dot Espie at liafa dot jussieu dot fr
- Subject: Re: C++ attributes ?
- From: "Martin v. Loewis" <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Wed, 1 Sep 1999 00:38:08 +0200
- CC: mrs at wrs dot com, Marc dot Espie at liafa dot jussieu dot fr, jason at yorick dot cygnus dot com, egcs-bugs at egcs dot cygnus dot com
- References: <199908311844.LAA10547@kankakee.wrs.com> <19990831231011.B19288@tetto.liafa.jussieu.fr>
> 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