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 11 22242
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); )
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) :-)
"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
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
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
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)
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
Thanks for the responses guys, Your advice and discussion of
the issues is as always much appreciated.
Regards,
Charles Sullivan
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
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
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 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
|
2 posts
views
Thread by Nemisis |
last post: by
|
reply
views
Thread by Michael |
last post: by
|
13 posts
views
Thread by Rex Mottram |
last post: by
|
1 post
views
Thread by eBob.com |
last post: by
| | | | | | | | | | | |