473,701 Members | 2,976 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 23231
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
3063
by: Mysooru | last post by:
Hi All, One of the ATL class..... template <class Base> class CComObject : public Base { public: typedef Base _BaseClass;
4
2527
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
2404
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
2603
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
1455
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
1146
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
9746
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
2812
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
1782
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
8737
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
8936
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
7827
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
6573
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...
0
5905
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4411
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4665
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3104
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2036
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.