Skip to content
This repository was archived by the owner on Jan 23, 2024. It is now read-only.

Unused function parameters - declare (how) or just disable warning? #17

Closed
HannesSommer opened this issue Apr 30, 2014 · 12 comments
Closed
Assignees

Comments

@HannesSommer
Copy link
Contributor

I currently wander what to do with unused parameters. Especially when it comes to overriding they are clearly unavoidable. But the compiler warning seem quit e useful (enabled implicitly with -Wextra)

With gcc there seem to be three options :

  1. have no name for the unused parameters
    Contra: bad when you want to start using it, maybe irritating when reading
    Pro: no macro needed (to create compiler independent code)
  2. declare it as unused (see http://stackoverflow.com/questions/3599160/unused-parameter-warnings-in-c-code for ideas)
    Contra: need macro and that macro needs a place (header file ...)
    Pro: can be nice to read and self documenting
  3. -Wno-unused-parameter
    Contra: killing useful warning
    Pro: simple

What do you think / how do you currently handle that?

@stephanemagnenat
Copy link

Personally I prefer the unused macro, as it makes things explicit.

@simonlynen
Copy link
Contributor

I think the cleanest solution is to use of the following:

void Process(int parameterA, bool /*parameterB*/) {
}
void Process(int parameterA, bool parameterB) {
  static_cast<void>(parameterB);
}

The following is bad, since not portable

void Process(int parameterA, bool parameterB __attribute__((__unused__))) {
}

@stephanemagnenat
Copy link

I did not know about the static_cast trick, not a bad solution but a bit geeky. Maybe have the name in comments is the simplest solution after all.

@markusachtelik
Copy link

+1 for Simons first solution.

Am 30.04.2014 um 12:10 schrieb "Simon Lynen" <[email protected]mailto:[email protected]>:

I think the cleanest solution is to use of the following:

void Process(int parameterA, bool /parameterB/) {
}

void Process(int parameterA, bool parameterB) {
static_cast(parameterB);
}

The following is bad, since not portable

void Process(int parameterA, bool parameterB attribute((unused))) {
}


Reply to this email directly or view it on GitHubhttps://github.com//issues/17#issuecomment-41780461.

@HannesSommer
Copy link
Contributor Author

I like Simon's first solution as well.

I guess we basically agreed on that.
We should include it in the guideline. Any objections?

@furgalep
Copy link

furgalep commented May 1, 2014

Yes, please include it in the guidelines!

And anyone feel free to update current code!

@furgalep furgalep closed this as completed May 1, 2014
@HannesSommer
Copy link
Contributor Author

I've just pushed a small perl script (to this rep) to do convert existing code based on the compiler warnings (e.g. Jenkin's raw output)

It is NOT perfect. So check the result after use (e.g. git diff).

@HannesSommer
Copy link
Contributor Author

Reopening to not forget the entry in the guidelines.

@HannesSommer HannesSommer reopened this May 2, 2014
@furgalep
Copy link

furgalep commented Sep 3, 2014

@HannesSommer , can you update the programming guidelines?

@HannesSommer
Copy link
Contributor Author

Yes, I will do that. The big problem with the guidelines is that it needs cleaning up and the github wiki language/interface is just a bit too limited to support that well. This is blocking me to work on it - maybe I manage to find a good way to improve the situation this time...

@furgalep
Copy link

furgalep commented Sep 3, 2014

Feel free to use Latex if that helps. For now, just add this to the list and close the issue.

@HannesSommer
Copy link
Contributor Author

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants