bug-gnulib
[Top][All Lists]
Advanced

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

Re: stdlib tweak


From: Bruno Haible
Subject: Re: stdlib tweak
Date: Wed, 23 Dec 2009 13:22:45 +0100
User-agent: KMail/1.9.9

Hi Jim,

>> > +static int (* _UNUSED_PARAMETER_ signature_check) (void (*) (void)) = 
>> > atexit;
> 
> Considering that this will appear in nearly every .c file in gnulib/lib,

You mean, in gnulib/tests/, I guess?

> Then, each use would be more concise:
> 
>     GL_SIG_CHECK (atexit, int, (void (*) (void)));

I like the idea: it provides an abstraction over this arcane C function pointer
syntax.

> how about a macro to encapsulate whatever idiom we use?
> Even if it means emitting that into config.h.

Since it's a utility macro only for the tests, I would much prefer to have it
in a file such as tests/macros.h, rather than polluting config.h with stuff
that exists only for the tests. This file tests/macros.h could also contain
the ubiquitous ASSERT macro. (I try to keep the tests as transparent and
will as little boilerplate complexity as possible. But a macro that is used
more than 200 times can certainly be refactored.)

>     #define GL_SIG_CHECK(fn, ret_type, param_list) \
>       static ret_type (* _UNUSED_PARAMETER_ signature_check) param_list = fn

In order to allow multiple uses of this macro in the same file, it should
probably use __LINE__. Also better call it CHECK_SIGNATURE: 'SIG' reminds
me too much of 'signal', and the prefix "GL_" is unneeded here.

> Otherwise we'd unnecessarily pollute the linker name space.

What do you mean by that? In a unit test, we can define all kinds of symbols
we like. We already have many tests which define global variables called
'o', 'sk', 'fd', 't1', 't2', 't3', 'g', 'h', 'i', 'j', etc. Do you see a
problem with that?

> > It also means that the gnulib guarantee that _UNUSED_PARAMETER_
> > expands to __attribute__((__unused__)) is a bit of a misnomer, as in this 
> > case,
> > signature_check is not a parameter.  Do we want to introduce a new alias,
> > _GL_UNUSED, and use that instead of _UNUSED_PARAMETER_?  (Unfortunately, we
> 
> I would prefer _GL_UNUSED, too.
> Not only a shorter name, but also more apt.
> If you want to deprecate _UNUSED_PARAMETER_ outside of gnulib,

I would leave _UNUSED_PARAMETER_ as it is. It is well named and frequently
used. You are now trying to use __attribute__((__unused__)) also for a
different case; that does not mean that _UNUSED_PARAMETER_ needs to be
changed.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]