Re: [Vala] _get_type() and G_GNUC_CONST
- From: Jan Hudec <bulb ucw cz>
- To: Aleksander Wabik <alex wabik gmail com>
- Cc: vala-list gnome org
- Subject: Re: [Vala] _get_type() and G_GNUC_CONST
- Date: Sat, 21 Aug 2010 21:26:28 +0200
On Wed, Aug 18, 2010 at 22:43:27 +0200, Aleksander Wabik wrote:
In glib doc for G_GNUC_CONST macro: "A const function doesn't examine
any values except its parameters, and has no effects except its return
value."
In 10-years-old mail:
http://mail.gnome.org/archives/gtk-devel-list/2001-May/msg00174.html
"_get_type() functions do have side effects, that of registering
a type upon first invocation."
So... as far as I can remember get_type() functions still has effect of
registering a type in the type system upon first call? So is
G_GNUC_CONST in vala-generated code valid?
Yes, the code is valid.
The point is that the function does not have any side-effects for any
practical purposes as everything that may depend on the type being allocated
either gets it from the function, or at least depends on something else that
does.
What the annotation means to compiler is that it is free to change the number
of calls to the function, reorder it with respect to other calls and memoize
it's return value for reuse. All of these optimizations are valid with type
getters, so the annotation is correct there.
--
Jan 'Bulb' Hudec <bulb ucw cz>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]