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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...