[cairo] Re: cairo c++ bindings
Bill Spitzak
spitzak at d2.com
Wed Nov 23 10:31:57 PST 2005
Benoit Perrot wrote:
> It seems to me that deriving from the C struct is highly dangerous:
> what happen if, for a reason or another the compiler decides to add
> informations before the "relevant" data block?
> Like in:
>
> class Matrix : public cairo_matrix_t
> {
> void init_identity()
> {
> cairo_matrix_init_identity(this);
> }
> };
This is actually ok as the call will actually conversion-cast the
Matrix* to a cairo_matrix_t*. This means it will move the pointer to
after any possible vtab that Matrix has. If it didn't do this, it would
not be possible to add virtual functions to a subclass of a
class/structure that does not have any. It would also be impossible to
do multiple inheritance.
What is a worry is that C++ will define the structure slightly
differently than C. But so much code relies on this that I think as long
as the cairo.h header file is in "extern "C" {...}" you can assumme it
will work.
Also I certainly do want any C++ wrapper to be inline, at least for all
methods that translate to a single cairo function call. Doubling the
procedure call overhead is unacceptable and will prevent any serious
users from using the C++ wrapper.
More information about the cairo
mailing list