Jump to content

RFC: macros for avoiding unused-param warnings


Recommended Posts

We have two macros for annotating code and preventing unused argument/variable warnings.

void Function(int argument1, float UNUSED(argument2))
{
ASSERT(argument1 == 0);
UNUSED2(argument1);
}

The first argument is used only in debug mode, so we need UNUSED2 to suppress the warning.

I never did like that name for the macro, but UNUSED_VARIABLE is a bit too long, and naming

UNUSED differently would be even worse in that regard, because it sometimes occurs several times in parameter lists.

I just had a simple idea - how about replacing UNUSED() with a C-style comment: float /*argument2*/ ?

That shortens the parameter list and leaves the UNUSED name for the current UNUSED2.

Any objections or suggestions for further improvement?

Link to comment
Share on other sites

The macro is valuable for Doxygen - we run it with

PREDEFINED = "UNUSED(x)=x"

so that it knows the names of the unused parameters, and I think using comments would break that.

(Also I think using comments is more ugly than the current macros, but that's not a particularly technical argument :))

Link to comment
Share on other sites

That's a very good point. I don't see a way to get commented-out names into Doxygen.

There are not THAT many unused parameters, but I agree they should be mentioned in Doxygen.

The commenting-out idea is dead in the water as far as I'm concerned.

Any ideas for better (but still short) names for the macros?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...