473,699 Members | 2,440 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

best way to suppress "unused" warning?

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)
{
puts(str);
return 0;
}

% gcc -c -W -Wall unused.c
unused.c:4: warning: unused parameter 'data'

I'm looking for an appropriate (safe, reasonably self-documenting) way
of suppressing that warning in cases where I expect it (thus I'm not
looking for the compiler flags to suppress the warning - I just want to
be able to mark the places I know about). I've used constructs like

data = data;
data++;
if (data != data) return;

And they all work but are a little too obfuscated for my taste. I'm sure
many other people have run into this - is there a recommended technique?

RM
Jun 27 '08 #1
13 9744
Rex Mottram said:
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)
{
puts(str);
return 0;
}

% gcc -c -W -Wall unused.c
unused.c:4: warning: unused parameter 'data'

I'm looking for an appropriate (safe, reasonably self-documenting) way
of suppressing that warning in cases where I expect it (thus I'm not
looking for the compiler flags to suppress the warning - I just want to
be able to mark the places I know about). I've used constructs like

data = data;
data++;
if (data != data) return;

And they all work but are a little too obfuscated for my taste. I'm sure
many other people have run into this - is there a recommended technique?
Lots of people use (void)data for this, and it's just as good a way as any
of those you mention, although I'd hesitate before claiming it's
"recommende d" because such a claim leaves some important questions
unanswered (for instance, "recommende d by whom?").

You might want to consider:

#define DISCARD_PARAMET ER (void)

Usage:

DISCARD_PARAMET ER data;

or you might prefer:

#define DISCARD_PARAMET ER(p) (void)p

Usage:

DISCARD_PARAMET ER(data);

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #2
On 25 Apr 2008 at 1:24, Richard Heathfield wrote:
Lots of people use (void)data for this, and it's just as good a way as
any of those you mention
Obfuscating your code to pacify your compiler or lint smacks to me of
letting the tail wag the dog.

Jun 27 '08 #3
Antoninus Twink wrote:
On 25 Apr 2008 at 1:24, Richard Heathfield wrote:
>Lots of people use (void)data for this, and it's just as good a way
as any of those you mention

Obfuscating your code to pacify your compiler or lint smacks to me of
letting the tail wag the dog.
In real life there may be coding standards that demand for this.

At one company I used to work for it was mandatory to use "-Wall -Werror",
or something eqivalent and all new code and on all older code once it got
touched.

It was a pain in the proverbian, but lead to much better code and lots of
yet unexplained faults mysteriously disappaered...

Bye, Jojo
Jun 27 '08 #4
In article <sl************ *******@nospam. invalid>,
Antoninus Twink <no****@nospam. invalidwrote:
>Lots of people use (void)data for this, and it's just as good a way as
any of those you mention
>Obfuscating your code to pacify your compiler or lint smacks to me of
letting the tail wag the dog.
It's a difficult balance to strike. I have at least once missed an
important warning because it was surrounded by unimportant ones that
I was expecting.

-- Richard

--
:wq
Jun 27 '08 #5
On Apr 24, 6:05*pm, Rex Mottram <r...@not.herew rote:
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)
{
* * *puts(str);
* * *return 0;

}

% gcc -c -W -Wall unused.c
unused.c:4: warning: unused parameter 'data'

I'm looking for an appropriate (safe, reasonably self-documenting) way
of suppressing that warning in cases where I expect it (thus I'm not
looking for the compiler flags to suppress the warning - I just want to
be able to mark the places I know about). I've used constructs like

* * * * data = data;
* * * * data++;
* * * * if (data != data) return;

And they all work but are a little too obfuscated for my taste. I'm sure
many other people have run into this - is there a recommended technique?
This is non-standard, but many compilers will not issue such
a warning when the comment /* ARGSUSED *? immediately
precedes the function:

/* ARGSUSED */
foo(char *str, void *data)
{
...
}

--
Fred Kleinschmidt

Jun 27 '08 #6
Richard Tobin wrote:
Antoninus Twink <no****@nospam. invalidwrote:
.... snip ...
>
>Obfuscating your code to pacify your compiler or lint smacks to
me of letting the tail wag the dog.

It's a difficult balance to strike. I have at least once missed
an important warning because it was surrounded by unimportant
ones that I was expecting.
Which, to me, points out the importance of handling those
'unimportant' warnings. I think there are very few which cannot be
eliminated by minor rewriting.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home .att.net>
Try the download section.
** Posted from http://www.teranews.com **
Jun 27 '08 #7
On 24 Apr 2008, Rex Mottram <re**@not.herew rote:
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)
foo(char *str, void *unused)
{
puts(str);
return 0;
}

% gcc -c -W -Wall unused.c
unused.c:4: warning: unused parameter 'data'
unused.c:4: warning: unused parameter 'unused'

OK, it doesn't *suppress* the warning. But it does make it
*reasonably* self-documenting ;-)

Dave

--
D.a.v.i.d T.i.k.t.i.n
t.i.k.t.i.n [at] a.d.v.a.n.c.e.d .r.e.l.a.y [dot] c.o.m
Jun 27 '08 #8
Joachim Schmitz wrote:
Antoninus Twink wrote:
Richard Heathfield wrote:
Lots of people use (void)data for this, and it's just as good
a way as any of those you mention
Obfuscating your code to pacify your compiler or lint smacks
to me of letting the tail wag the dog.

In real life there may be coding standards that demand for this.
Of course, tail wagging the dog is standard policy in many
avenues of life. That doesn't mean it's sensible.
At one company I used to work for it was mandatory to use
"-Wall -Werror", or something eqivalent and all new code and
on all older code once it got touched.
So if the compiler ever get's upgraded, you may have to 'correct'
thousands of lines of perfectly correct code because the compiler
writers decided to add another warning? Brilliant.

Did you have to rewrite third party library sources as well?
It was a pain in the proverbian, but lead to much better code
Warning free is not a measure of 'better'. But I'm in a minority
on that.
and lots of yet unexplained faults mysteriously disappaered...
I'm sure it also lead to the appearance (albeit rare) of
mysterious faults that went undiscovered for some time until a
critical moment precisely because all the programmers have
been conditioned to write code that eludes diagnostics and
static analysis.

Ever heard the term superbugs. ;-)

--
Peter
Jun 27 '08 #9
Peter Nilsson said:

<snip>
Warning free is not a measure of 'better'. But I'm in a minority
on that.
But not a minority of one. I happen to agree with you on this.
Nevertheless, *to a first approximation*, a low warning count is better
than a high warning count. If code generates a vast number of warnings,
that is typically not a good sign, although there might be a good reason
for it. (Think pulse rate - 160 heartbeats a minute is not generally
considered healthy, but if the measuree has just completed a run of 10,000
metres it probably counts as pretty low!)

<snip>

--
Richard Heathfield <http://www.cpax.org.uk >
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Jun 27 '08 #10

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

Similar topics

11
9415
by: Daniele Benegiamo | last post by:
Is the following program standard-compliant? I've compiled it with some compilers and no errors or warnings are produced, but this is not a demonstration. The "incriminated" part is the declaration: extern "C" struct X; that is then defined as:
81
7305
by: Matt | last post by:
I have 2 questions: 1. strlen returns an unsigned (size_t) quantity. Why is an unsigned value more approprate than a signed value? Why is unsighned value less appropriate? 2. Would there be any advantage in having strcat and strcpy return a pointer to the "end" of the destination string rather than returning a
6
2574
by: Chris Stankevitz | last post by:
At link time, MSVC determines some of my libraries are unused and doesn't link them into my exe. This undesirable feature causes problems when I employ the factory pattern. With the factory pattern, the app decides at run time which code to use. Is there a link option to turn of this feature? MSVC 7.1 .net 2003 69462-270-0000007-18536 Thanks,
0
988
by: Steve B. | last post by:
Hello I'm building a Web service that have some methods. I've also two datasets class : DataSet1 and DataSet2. If I add a method in my WS that waits for or return either DataSet1 and DataSet2, the DataSet is embedded in the WSDL so the client application can use them as typed DataSet, which is working well with VS.
20
1646
by: Andreas Griesmayer | last post by:
Hi, following piece of code causes a strange behavior when compiled with GCC (Linux, Gentoo 3.3.5.20050130-r1). read() is called twice although only called once, the first time before the first statement of main ! I guess there is some call to another read-function my function is wrongly linkted to, it works fine if read() is renamed or static. Compilation does not produce any warnings. Can anyone explain this behavior to me or...
11
23231
by: Charles Sullivan | last post by:
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
5
14430
by: Glen Buell | last post by:
Hi all, I have a major problem with my ASP.NET website and it's SQL Server 2005 Express database, and I'm wondering if anyone could help me out with it. This site is on a webhost (WebHost4Life) and was running fine and dandy, until I decided I needed to add some additional stored procedures to the database.
2
6002
by: CGatto | last post by:
Hi, We have just started getting the following error during compiles of our forms-based application. We are developing in VS2008, VB.Net, with Team Foundation Server-based source control. Full error message is: "Unable to copy file "obj\Debug\OurProjectName.xml" to "bin\Debug\OurProjectName.xml". Access to the path 'obj\Debug\OurProjectName.xml' is denied."
11
6788
by: arnuld | last post by:
C takes input character by character. I did not find any Standard Library function that can take a word as input. So I want to write one of my own to be used with "Self Referential Structures" of section 6.5 of K&R2. K&R2 has their own version of <getwordwhich, I think, is quite different from what I need: <getwordwill have following properties: 1.) If the word contains any number like "beauty1" or "win2e" it will
0
8623
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
9185
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...
1
8935
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7773
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
6540
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
5879
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
4389
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
4636
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2015
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.