473,594 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 23216
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.c om...
>
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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3058
by: Mysooru | last post by:
Hi All, One of the ATL class..... template <class Base> class CComObject : public Base { public: typedef Base _BaseClass;
4
2510
by: J. Campbell | last post by:
From reading this forum, it is my understanding that C++ doesn't require the compiler to keep code that does not manifest itself in any way to the user. For example, in the following: { for(int i = 0; i < 10; ++i){ std::cout << i << std::endl; for(int j = 0; j < 0x7fffffff; ++j){} } }
39
2390
by: TonyJeffs | last post by:
Great book - I like the way that unlike other books, AC++ explains as much as possible about every piece of code discussed, so I'm not left thinking, "well...OK... I get line 12, but I wonder what the rest of it means...". Still, I have some questions, that are frustrating me:- Grateful for any comments. 1. What is the difference between #include <iostream> // (or any include file) which is used in this
4
2595
by: neo | last post by:
I want to make one function for pass "n Parameter" with respective functionality, "..." use for parameter but I am not understand how use "..." in function and what is the technical name of this technique? Tell me some links for study "n Parameters" techniques in C++. Regards, -aims
2
1447
by: Nemisis | last post by:
Hi, Is it possible to pass in an object and parameter into a function and return it as a string. i.e. To make a call to the function i would put the following Dim str as String = MyTestFunction(myObject.Parameter)
0
1129
by: Michael | last post by:
Hi. I am building asp page. One of the <tdcoomponents should include text field from database which is include whole HTML page taken once from another web site. And ofcause this text consist of their HTML tag. The result of printing makes my page be streached(not my design ofcause) The task is to prevent any of parameters inside the text field like "width" to change my structure(my sizes-in my case 600). The script i am using is simple ...
13
9720
by: Rex Mottram | last post by:
I'm using an API which does a lot of callbacks. In classic callback style, each routine provides a void * pointer to carry user-defined data. Sometimes, however, the user-defined pointer is not needed which causes the compiler to spit out a "helpful" warning. For example: % cat unused.c #include <stdio.h> int foo(char *str, void *data) {
1
2796
by: eBob.com | last post by:
I have some code which is trying to determine where text will wrap in a custom text box (which Inherits from Control). It determines the number of characters which will fit in the first line, but then encounters an exception when it calls MeasureCharacterRanges to see if the next character, i.e. the one destined to become the first character of the second line, will fit. The message says only "Invalid parameter" - it does not say which...
3
1781
BRawn
by: BRawn | last post by:
Hi, I'm writing an application which needs SQL parameters to be passed, and even though I've assigned parameters to the stored procedure, I keep getting the following error message from the debugger: 'usp_PopulateManualSelectionForEdit' expects parameter '@BinID', which was not supplied. The stored proc: CREATE PROCEDURE usp_PopulateManualSelectionForEdit
0
7947
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7880
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8255
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8242
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6665
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
1486
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1217
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.