« Home | PayPal Subscriptions Outage Finally Resolved » | Web Based Power Point Presentations » | A New DUNS Number » | [YouTube] Mindstorms Autofabrik » | Roll Your Own Firewall, Part II » | Ah the enchanting life of a consultant. » | Health Savings Accounts » | Roll Your Own Firewall, Part I » | Rack'em Stack'em » | Installing Subversion on legacy Red Hat distros »

Dealing with C++ "Unused Parameter" Warnings

Generally, when I am working with clients I try to get everyone on the team to agree to a "no compiler warnings" policy and immediately turn on the "warnings as errors" switch. Thereafter, any compiler warning is automatically treated like an error and the build will fail. Unfortunately, when stepping into a project where most of the code was written long ago, there may be hundreds if not thousands of compiler warnings. The only solution is to investigate and fix (or suppress) each one. So how do you suppress the unused parameter warnings when you legitimately don't use the argument? There are three ways: 1. #pragma unused. #pragmas are compiler specific and should be avoided. However, if your compiler supports it, you can use it as follows:

void my_function(int32 foo)
{
#pragma unused foo;
}

2. Comment the Argument. Additionally, you can comment out the argument. The compiler will not give you an unused warning:

void myfunction(int /* arg */)
{
}

3. Cast to void. Casting an unused variable to void will always
stop the warning.

#define UNUSED_ARGUMENT(x) (void)x
void myfunction(int arg )
{
UNUSED_ARGUMENT(arg);
}

Labels: ,

What if the argument has a default value, but is not used?

like

function(bool foo=true) ?

> function(bool foo=true) ?

comment out the value?

I use the macro here to handle unused parameter warnings.

#define UNUSED_ARG (x)



void myfunction(int UNUSED_ARG(arg) )
{

}

Bonjorno, www.agavemountain.com!
[url=http://doveacquistarecialisonlinerp.pun.pl/ ]Compra cialis [/url] [url=http://acquistoviagraonlineta.pun.pl/ ]Acquisto viagra generico[/url] [url=http://acquistolevitragenericomp.pun.pl/ ]Comprare levitra online[/url] [url=http://doveacquistarecialistr.pun.pl/ ]Compra cialis online[/url] [url=http://venditaviagrati.pun.pl/ ]Acquisto viagra [/url] [url=http://compracialisco.pun.pl/ ]Vendita cialis [/url]

Post a Comment