473,902 Members | 3,601 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
11 23257
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3073
by: Mysooru | last post by:
Hi All, One of the ATL class..... template <class Base> class CComObject : public Base { public: typedef Base _BaseClass;
4
2550
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
2438
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
2612
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
1464
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
1157
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
9782
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
2822
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
1793
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
9997
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
11277
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
10866
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
10497
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
9672
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
8045
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
6084
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4724
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
2
4305
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.