GNOME Bugzilla – Bug 446874
g_type_ensure()
Last modified: 2007-06-14 20:50:47 UTC
Works around the G_GNUC_CONST in declaration of get_type() functions by forcing a call: #define g_type_ensure(type) \ G_STMT_START { volatile GType __dummy = (type); } G_STMT_END So you write: g_type_ensure (GTK_TYPE_MESAGE_DIALOG); and be safe. Ref: http://wingolog.org/archives/2005/03/24/98 and others. Logs of #gtk+ from few minutes ago.
i don't like the idea of adding such a thing to glib at all. the flagging of _get_type functions as GNUC_CONST is *wrong* in the first place, glib is abusing gcc there, and i'd personally prefer to get rid of all such abuses. adding API for users to work around glib's own insanity is taking it too far. if you really want to "fix" this abuse the right way, not forgo GNUC_CONST flagging and make the world a better place, please file a bug against gcc for __attribute__((constant_registry)) or a similar name, that offers the semantics of pure/const but guarantees to ever only optimize calls that gcc can prove are *successive* and not initial calls to a function.