[Bf-committers] unused function args & warnings.

Campbell Barton ideasman42 at gmail.com
Mon Oct 18 02:52:48 CEST 2010


On Wed, Oct 13, 2010 at 9:27 PM, Campbell Barton <ideasman42 at gmail.com> wrote:
> On Wed, Oct 13, 2010 at 11:51 AM, Martin Poirier <theeth at yahoo.com> wrote:
>>
>>
>> --- On Tue, 10/12/10, Campbell Barton <ideasman42 at gmail.com> wrote:
>>
>>> Id like to enable warnings in GCC for
>>> unused args, however this gives
>>> a lot of warnings for functions which have args which are
>>> needed so
>>> the function can be used as a callback.
>>> This would only apply to C code in blender's source/ and
>>> intern/ dirs,
>>> since it doesn't make sense to modify external libs for
>>> this.
>>
>> What do you expect to catch with that warning? Is it related to a real error you found in the sources?
>>
>> Martin
>
> This mostly just helps reduce general sloppiness in blenders code - as
> with unused variables.
>
> A few times I have gone to some effort to get vars passed along to a
> function (which weren't originally accessible from the caller), only
> to find it wasn't used.
> But this is still fairly rare, so Ill put it down to me being
> pedantic, that I like to know args are used without having to
> read/search the source manually.
>
> This has got a little worse with 2.5 functions being moved around can
> cause this.
> GCC has some useful warnings -Wunused-parameter,
> -Wunused-but-set-parameter, -Wunused-label which we could make use of
> which I think would help in the long run.
>
>
> Regarding how to do this, I'd prefer the UNUSED() macro, in the
> function arguments, mainly because with (void)arg;, once arg becomes
> used their is no error whereas with the GCC __attribute__ it does, for
> portability we can use defines ofcourse.

To follow up on this topic.

-Wunused-parameter is now used for scons/linux and cmake/gcc,
for cmake it should not complain about this anymore.
I have it disabled this for the render code and makesrna since it
could mess up merging the render branch and the generated code from
makesrna causes this warning too.

There were many more cases of this then I expected, to give a quick
idea, here is the number of times UNUSED now appears in blenders
source.

cat `find -name "*.[ch]"`  | tr -cs 'A-Za-z' '\n' | grep ^UNUSED$ | wc -l
2342


More information about the Bf-committers mailing list