Re: [patch] add G_GNUC_WARNUNCHECKED define



On Tue, Jul 06, 2004 at 08:43:49AM +0200, Owen Taylor wrote:
> On Mon, 2004-07-05 at 18:04, Arjan van de Ven wrote:
> > Hi,
> > 
> > gcc versions 3.4 and later have an attribute that you can give to a function
> > that will cause gcc to warn if you don't check/use the return value of such
> > function. The patch below adds a G_GNUC_WARNUNCHECKED define for this
> > attribute. A typical use for this is in realloc() definitions where not
> > using the return valueof such functions is always a bad bug in the program.
> > The patch below thus adds this attribute to g_realloc() and g_try_realloc().
> 
> Sounds vaguely useful; I'm not sure I see a reason to deviate from the
> GCC name other than perhaps length. G_GNUC_WARN_UNUSED_RESULT is
> certainly more descriptive.

ok fair enough

> Is the version check right? It's the info page for gcc-3.3.2 that
> I have here.

some distributions have this backported to their gcc 3.3 compilers ;)

> Another concern is that it isn't clear to me if we start adding this
> attribute where to stop. There are a *ton* of functions in GLib
> and GTK+ that return allocated memory. There are even more functions
> that have no side effects other than their return value. In either
> of these cases, not using the return value is definitely a bug.
> 
> What's the criterion for adding the attribute, simply that we think
> it's likely that someone would make the mistake?

well, g_realloc is one of the more typical "clear cut" cases I guess. 
Where to draw the line for the gray area is a bit hard, I personally don't
see the use of for example marking g_malloc() with this attribute.

Attachment: pgpvk80m8x8WL.pgp
Description: PGP signature



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