468,463 Members | 1,910 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

Clean up "unused parameter" compiler warnings?


I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.

Is there an "approved" way of dealing with this
which will work on all or (most all) C compilers
and OSes?

Thanks for your help.

Regards,
Charles Sullivan

Sep 5 '06 #1
11 21527
Charles Sullivan wrote:
In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.
Then you get a warning that the value of arg2 is never
used. Ideally, turn off all these stupid warnings. But on
compilers where that isn't possible, I do this:

NOT_USED(arg2);

and then in a piece of header file specific to that compiler,
define something that will work for that compiler and not
produce a warning. Here's some options from compilers
I use:

#define NOT_USED(x) ( (void)(x) )

#define NOT_USED(x) ( *(volatile typeof(x) *)&(x) = (x); )

Sep 5 '06 #2
Old Wolf a écrit :
Charles Sullivan wrote:
>>In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.


Then you get a warning that the value of arg2 is never
used. Ideally, turn off all these stupid warnings. But on
compilers where that isn't possible, I do this:

NOT_USED(arg2);

and then in a piece of header file specific to that compiler,
define something that will work for that compiler and not
produce a warning. Here's some options from compilers
I use:

#define NOT_USED(x) ( (void)(x) )

#define NOT_USED(x) ( *(volatile typeof(x) *)&(x) = (x); )
Extensions ARE useful!

This is a wonderful application of typeof. (Also supported
by a certain windows compiler I know) :-)

Sep 5 '06 #3

"Charles Sullivan" <cw******@triad.rr.comwrote in message
news:pa***************************@triad.rr.com...
>
I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.

Is there an "approved" way of dealing with this
which will work on all or (most all) C compilers
and OSes?

Thanks for your help.

Regards,
Charles Sullivan
*Some* compilers will recognize the non-standard
/* ARGSUSED */
comment immediately above the function definition:

/* ARGSUSED */
int funct1( int arg1, int arg2, int arg3 ) {
/* Body of the function here */
}

Again, this is NOT standard, but you could always try it
and see if your compiler shuts up.
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Sep 5 '06 #4
Charles Sullivan wrote:
I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.

Is there an "approved" way of dealing with this
which will work on all or (most all) C compilers
and OSes?
(void) arg1;

Simple, Standard, likely to work on any compiler that complains about
unused parameters.

Robert Gamble

Sep 5 '06 #5
Charles Sullivan schrieb:
I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.
In the function definition, I usually do (for unused arg2 and arg3):

int funct1(int arg1, int /*arg2*/, int /*arg3*/)
{
/* ... */
}

....or leave away the parameter name.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Sep 5 '06 #6
Thomas J. Gritzan said:
Charles Sullivan schrieb:
>I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

In the function definition, I usually do (for unused arg2 and arg3):

int funct1(int arg1, int /*arg2*/, int /*arg3*/)
{
/* ... */
}

...or leave away the parameter name.
....and get a syntax error for your trouble.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 5 '06 #7
Richard Heathfield wrote:
Thomas J. Gritzan said:
>In the function definition, I usually do (for unused arg2 and arg3):

int funct1(int arg1, int /*arg2*/, int /*arg3*/)
{
/* ... */
}

...or leave away the parameter name.

...and get a syntax error for your trouble.
Oops, another C++ specific, well, extension, I wasn't aware of.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Sep 5 '06 #8
Thanks for the responses guys, Your advice and discussion of
the issues is as always much appreciated.

Regards,
Charles Sullivan

Sep 6 '06 #9
jacob navia wrote:
Old Wolf a écrit :
Charles Sullivan wrote:
In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.
Then you get a warning that the value of arg2 is never
used. Ideally, turn off all these stupid warnings.
Or just ignore them!!

Compilers can generate warnings for any reason they like.
It is futile wasting time trying to write code that doesn't issue
any warning on any compiler.

[I'm thinking of writing a compiler that issues the diagnostic
"Warning: the source file compiled with no warnings. Don't think
that just because there aren't any warnings that the code is
necessarily correct!" ;-]
But on compilers where that isn't possible, I do this:

NOT_USED(arg2);

and then in a piece of header file specific to that compiler,
define something that will work for that compiler and not
produce a warning. Here's some options from compilers
I use:

#define NOT_USED(x) ( (void)(x) )

#define NOT_USED(x) ( *(volatile typeof(x) *)&(x) = (x); )

Extensions ARE useful!

This is a wonderful application of typeof.
Wonderful?!! Removing a redundant warning?!

I'm quite sure there are _better_ examples of typeof.

[There are certainly more correct macros. ;-) But even after
correcting,
the second macro is slightly flawed in that it doesn't work properly on
register qualified parameters.]

--
Peter

Sep 6 '06 #10
Charles Sullivan wrote:
>
I have a number of functions, e.g.:
int funct1( int arg1, int arg2, int arg3 );
int funct2( int arg1, int arg2, int arg3 );
int funct3( int arg1, int arg2, int arg3 );

that are called via pointers in a table, with the
same parameters regardless of the particular
function.

In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.

I can silence the compiler by adding a statement
like:
arg2 = arg2;
to each affected function, but that seems sort of
clumsy.
If you are using GCC, you can use this:

http://sourcefrog.net/weblog/softwar.../C/unused.html

HTH,
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
http://en.wikipedia.org/wiki/Why_I_Am_Not_a_Christian
http://en.wikipedia.org/wiki/Why_I_Am_Not_a_Muslim
http://en.wikipedia.org/wiki/Strong_atheism
Sep 6 '06 #11
Old Wolf wrote:
Charles Sullivan wrote:
>>In some of the functions, one or more of the
parameters are unused. This can result in the
compiler warning that such and such a parameter
is unused.
Ideally, turn off all these stupid warnings. But on
compilers where that isn't possible, I do this:

NOT_USED(arg2);

and then in a piece of header file specific to that compiler,
define something that will work for that compiler and not
produce a warning.
I like that approach as well.
Here's some options from compilers
I use:

#define NOT_USED(x) ( (void)(x) )

#define NOT_USED(x) ( *(volatile typeof(x) *)&(x) = (x); )
I have one that responds to (if I recall correctly)

#define NOT_USED(x) if(x);

--
Thad
Sep 11 '06 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mysooru | last post: by
4 posts views Thread by J. Campbell | last post: by
39 posts views Thread by TonyJeffs | last post: by
4 posts views Thread by neo | last post: by
reply views Thread by Michael | last post: by
13 posts views Thread by Rex Mottram | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.