Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Need your experience: is "(void)param;" to avoid unused variablewarnings well known for you?

Reply
Thread Tools

Need your experience: is "(void)param;" to avoid unused variablewarnings well known for you?

 
 
Dombo
Guest
Posts: n/a
 
      04-03-2012
Op 02-Apr-12 13:16, Qi schreef:
> Hi all,
>
> Let me show some code first,
>
> void someFunction(int param)
> {
> (void)param; // param is not used in this function. This line is
> // just to silence the compiler warning about unused param.
> }
>
> Please note the "(void)param".
> Is that usage common or well known for you?
> Or you rarely saw it? Or even it's weird to you?


I have seen it before, but not frequently and usually wrapped in macro.

> Just your experience is enough, no need to debate for it's good
> or bad.
>
> The reason I ask this is, in my another thread, some very veteran
> C++ developers said they rarely saw that kind of usage.
> That makes me a little nervous because I used it a lot in my
> code to *improve* the code readability.
> If it's not well known trick then it reduces code readability
> and then I'm going to change my code about that.
>
> That's not only about coding style but also about code readability.


I agree that code readability (easy to understand) is very important.
Personally I prefer to just comment out the parameter name. It is less
typing and is pretty clear even to less experienced coders. The purpose
of (void)param; will not be obvious to everyone,unless wrapped in a
macro with an obvious name.
 
Reply With Quote
 
 
 
 
Stuart Redmann
Guest
Posts: n/a
 
      04-04-2012
On 2 Apr., 13:16, Qi <(E-Mail Removed)> wrote:
> Hi all,
>
> Let me show some code first,
>
> void someFunction(int param)
> {
> * * (void)param; // param is not used in this function. This line is
> // just to silence the compiler warning about unused param.
>
> }
>
> Please note the "(void)param".
> Is that usage common or well known for you?
> Or you rarely saw it? Or even it's weird to you?


Never seen it in 15 years of C++ programming. Looks also weird to me.

Regards,
Stuart
 
Reply With Quote
 
 
 
 
Qi
Guest
Posts: n/a
 
      04-05-2012
Thanks all for your input.

Here is my update.

I did a search, found more than 400 (void)param in about
35K lines of code.
I removed more than 200, and found it really worth my time.
Because I found even I (void) some parameters, latter
I added code to use the parameter but forgot to remove
the (void). That's terribly confusing and significantly
reduced code readability.

Now I use the commented out parameter name,
void func(int /*param*/);
Then there is no way to use an "unused" parameter.
Safe and clear.

Also I removed parameters that will never be used.

There are still more than 100 (void) in my code.
Most are in tool-generate code so I won't fix them
otherwise I need to change the tool a lot.
Others are in unit test that less harmful.


--
WQ
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
survey: cool but not so well-known python apps Alia Khouri Python 0 04-26-2009 12:42 PM
any way to avoid warnings about unused outputs in XST? Ken Cecka VHDL 10 03-02-2009 10:51 PM
Re: Is this phase-accumulator trick well-known??? Mike Treseler VHDL 0 02-08-2009 07:17 PM
List mutation method gotcha - How well known? Hendrik van Rooyen Python 20 03-16-2008 09:55 AM
well-known Internet sites which use Java based web servers Mladen Adamovic Java 3 10-24-2005 09:48 PM



Advertisments