[sane-devel] How to avoid gcc warnings

Frank Zago sane at zago.net
Wed Nov 21 01:13:27 UTC 2007


jazz_johnson at verizon.net a écrit :
> On Tuesday 20 November 2007, Mattias Ellert wrote:
>   
>> 20 nov 2007 kl. 12.32 skrev Volker Grabsch:
>>     
>>> On Mon, Nov 19, 2007 at 11:36:20AM -0500, m. allan noah wrote:
>>>       
>>>> ok, lets start by saying that lots of other sane backends produce
>>>> warnings, and i am probably running a newer version of gcc than you,
>>>> so it's not a requirement that we remove all of them. it's just a pet
>>>> peev of mine.
>>>>
>>>> 1. if you put a little 'arg = arg;' line in the function, gcc will
>>>> shutup about the param.
>>>>         
>>> I'd rather recommend:
>>>
>>>    (void)arg;
>>>
>>> because this command has no "action". ('arg = arg;' is an assigment)
>>> This solution also works better for 'const' arguments.
>>>       
>> You can also leave the parameter unnamed in the declaration:
>>
>> sense_handler (int scsi_fd, u_char * result, void*)
>>
>> This will also get rid of the warning.
>>
>> 	Mattias
>>     
>
> Leaving out the parameter name  gives me an error:
>
> In file included from hs2p.c:95:
> hs2p-scsi.c: In function 'sense_handler':
> hs2p-scsi.c:384: error: parameter name omitted
> make[1]: *** [hs2p.lo] Error 1
> make[1]: Leaving directory `/var/tmp/portage/sane-backends-1.0.18/backend'
> make: *** [all-recursive] Error 1
>
>   
You can use __sane_unused__ :
sane_init (SANE_Int * version_code, SANE_Auth_Callback __sane_unused__
authorize)

Or use UNUSEDARG (grep sources for that one)

Frank



More information about the sane-devel mailing list