G_GNUC_CONST with _get_type() usage



adding G_GNUC_CONST all over the place to _get_type functions
is actually misleading to gcc.

`const'
     Many functions do not examine any values except their arguments,
     and have no effects except the return value.  Such a function can
     be subject to common subexpression elimination and loop
     optimization just as an arithmetic operator would be.

_get_type() functions do have side effects, that of registering
a type upon first invocation.

i'm not going back through the code to get rid of all these,
though that would be the Right Thing to do. as it stands now,
people will just have to be aware that code like:

/* gtk_vscale_get_type() hasn't been called yet */
gtk_vscale_get_type ();
printf ("vscale type_id=%u\n", g_type_from_name ("GtkVScale"));

will not work under gcc, because it legitemately optimizes
the function call away.

[i did remove G_GNUC_CONST from gtk_type_class() however, as that
 just lead to a segfault in a similar scenario because
 class-initialization was "optimized away"]

---
ciaoTJ





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]