In GNOME's gobject object-oriented code, each type has a "get_type" function.
Something like, eg:
GType
pango_layout_line_get_type(void)
{
static GType our_type = 0;
if (our_type == 0)
our_type = g_boxed_type_register_static (I_("PangoLayoutLine"),
(GBoxedCopyFunc) pango_layout_line_ref,
(GBoxedFreeFunc) pango_layout_line_unref);
return our_type;
}
Since these functions are called quite frequently (as part of casts among other
things), people have started marking them with __attribute__((const)) so the
compiler can optimize away multiple calls to them. However, there is a down
side to it. Sometimes one needs to make sure the type is registered, so they
call the _get_type() function to ensure that, but the compiler, seeing the
((const)) attribute, optimizes away the call.
This is of course a bug to mark functions with side-effects as ((const)).
That's why a new function attribute like "idempotent" is useful. What it means
is that subsequent calls to this function return the same value as the first
call, have no side-effect, and can be optimized away, but not the first call...
Thanks,
--
Summary: Function __attribute__ ((idempotent))
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: gnu at behdad dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32911