Re: Overhead of type casting when using GObject system
- From: Chris Vine <chris cvine freeserve co uk>
- To: Emmanuele Bassi <ebassi gmail com>
- Cc: GTK Devel List <gtk-devel-list gnome org>
- Subject: Re: Overhead of type casting when using GObject system
- Date: Mon, 11 Feb 2013 13:24:15 +0000
On Sun, 10 Feb 2013 11:08:31 +0000
Emmanuele Bassi <ebassi gmail com> wrote:
> On 9 February 2013 12:43, Lanoxx <lanoxx gmx net> wrote:
> >> However those cast checks can be disabled at compile time removing
> >> the overhead, so GTK_WIDGET(foo) would be equivalent to (GtkWidget
> >> *) foo.
> >
> > Ah thats good to know. But still I believe that most applications
> > that are shipped with gnome are not compiled that way.
>
> stable releases of gtk automatically disable cast checks for internal
> usage; it's actually pretty easy to do, you just need to define
> G_DISABLE_CAST_CHECKS symbol before including glib-object.h.
But be very careful about defining this symbol in C++ code which has
templated or inline functions which contain code using GObject style
casts: if all translation units do not see the same definition (or
non-definition) of G_DISABLE_CAST_CHECKS then it is easy to break the
extremely tedious C++ one-definition rule without a diagnostic.
Although this is undefined behaviour, in practice the results won't be
wholly egregious: in a case where the compiler decides not to inline
the function (ie it emits linkable object code) you may or may not get
the C style cast you were hoping for, depending on what code the linker
actually links to.
You can get something similar in C99 if you have both inline and
external definitions of a function, but I believe the effect is
implementation defined rather than undefined.
The best thing, particularly in C++ code, is to pass this symbol using
the -D compiler flag (say via the CFLAGS and CXXFLAGS environmental
variables) and recompile everything which might see the header files in
question, including any library of which the header file containing the
templated or inline functions forms part, rather than by picking
through and defining it in user code before including glib-object.h.
Chris
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]