[comp.lang.c++] What do I do with unused arguments?

brad@bwilab3.UUCP (Bradley Ward) (12/08/90)

When I write a callback routine such as those used by X windows,
many times I don't need to use the "client_data" argument.  But
the C++ compiler issues a "unused argument" warning.  I hate to
have warnings generated, so I have been doing stuff like putting
the statement "client_data = client_data;" in the callback simply
to eliminate this compiler warning.  (I hope the optimizer is smart
enought to take this out!).  

Any ideas on how to handle this more elegantly ?

Bradley Ward                                      Phone: 404-396-4292
BRADLEY WARD, INC.                                FAX:   404-396-6509
5901-A Peachtree Dunwoody Road, N.E. Suite 415   
Atlanta, Georgia   30328
...!uunet!gatech!galbp!bwilab3!brad

roman@hri.com (Roman Budzianowski) (12/10/90)

Define the callback as:

void acallback(Widget w, caddr_t, caddr_t closure)
{}

i.e. omit the variable you are not using.

thomas@hpugrca.HP.COM (Thomas Buenermann) (12/12/90)

> the C++ compiler issues a "unused argument" warning.  

You might try something like

void startCB (Widget,caddr_t client_data)
{
printf("Button %s action.\n",client_data);
}

which does not generate warnings on our C++. I also like
to get rid of warnings this way...

Regards,
Thomas

jgro@lia (Jeremy Grodberg) (12/13/90)

In article <133@bwilab3.UUCP> brad@bwilab3.UUCP (Bradley Ward) writes:
>When I write a callback routine such as those used by X windows,
>many times I don't need to use the "client_data" argument.  But
>the C++ compiler issues a "unused argument" warning.  
>
>Any ideas on how to handle this... elegantly ?

Leave the names of the unused varaibles out of the declaration of
the callback routine.  In other words, if the callback is

int callback(int x, int y, int z)

and you don't use y, then just declare it as

int callback(int x, int, int z)

and then you won't get any warnings about the unused y.


-- 
Jeremy Grodberg      "I don't feel witty today.  Don't bug me."
jgro@lia.com          

mat@mole-end.UUCP (Mark A Terribile) (12/14/90)

> When I write a callback routine such as those used by X windows,
> many times I don't need to use the "client_data" argument.  But
> the C++ compiler issues a "unused argument" warning.  I hate to
> have warnings generated, so I have been doing stuff like putting
> the statement "client_data = client_data;" in the callback simply
> to eliminate this compiler warning....

It seems to me we've seen this three times in six weeks.  comp.lang.c has a
Frequently Asked Qestions list that is posted periodically.  Is it time for
comp.lang.c++ to get a FAQ of its own?

If I could promise the time to do it, I'd volunteer.  For the present, I can't.
But if anyone would like to, here's one reader who would be grateful.

Oh, the correct answer to the question is  ReadTheFructatingManual!  The useful
answer is `Omit the argument name in the argument list, but leave the type (as
though you were casting).'
-- 

 (This man's opinions are his own.)
 From mole-end				Mark Terribile

ahodgson@athena.mit.edu (Antony Hodgson) (12/18/90)

Just place the argsused pragma in front of the offending function.

Tony Hodgson
ahodgson@hstbme.mit.edu