Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > senseless statement?

Reply
Thread Tools

senseless statement?

 
 
Tobias Blass
Guest
Posts: n/a
 
      02-05-2011
Hi all,
I'm just reading fetchmail source code and found the following lines
/* env.c, line 37 */
void envquery(int argc,char **argv)
{
/* ... */
(void)argc;
(void)argc;
/*...*/
}

envquery is called (from main()) like this

envquery(argc,argv);

I don't really get the sense of these two (void)argc; . Does this have
any special meaning or is it really "take the value of argc and ignore
it"?

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-05-2011
On 02/ 6/11 11:02 AM, Tobias Blass wrote:
> Hi all,
> I'm just reading fetchmail source code and found the following lines
> /* env.c, line 37 */
> void envquery(int argc,char **argv)
> {
> /* ... */
> (void)argc;
> (void)argc;
> /*...*/
> }
>
> envquery is called (from main()) like this
>
> envquery(argc,argv);
>
> I don't really get the sense of these two (void)argc; . Does this have
> any special meaning or is it really "take the value of argc and ignore
> it"?


Yes, probably to silence an over enthusiastic compiler of lint.

It's a shame C hasn't embraced C++'s use of unnamed parameters.

--
Ian Collins
 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      02-05-2011
On 02/ 6/11 11:29 AM, Ian Collins wrote:
> On 02/ 6/11 11:02 AM, Tobias Blass wrote:
>> Hi all,
>> I'm just reading fetchmail source code and found the following lines
>> /* env.c, line 37 */
>> void envquery(int argc,char **argv)
>> {
>> /* ... */
>> (void)argc;
>> (void)argc;
>> /*...*/
>> }
>>
>> envquery is called (from main()) like this
>>
>> envquery(argc,argv);
>>
>> I don't really get the sense of these two (void)argc; . Does this have
>> any special meaning or is it really "take the value of argc and ignore
>> it"?

>
> Yes, probably to silence an over enthusiastic compiler of lint.


Make that "compiler *or* lint".

--
Ian Collins
 
Reply With Quote
 
Ike Naar
Guest
Posts: n/a
 
      02-05-2011
On 2011-02-05, Tobias Blass <(E-Mail Removed)> wrote:
> void envquery(int argc,char **argv)
> {
> /* ... */
> (void)argc;
> (void)argc;
> /*...*/
> }
>
> envquery is called (from main()) like this
>
> envquery(argc,argv);
>
> I don't really get the sense of these two (void)argc; . Does this have
> any special meaning or is it really "take the value of argc and ignore
> it"?


Probably a way to suppress compiler warnings for 'unused parameter'.
 
Reply With Quote
 
Ben Bacarisse
Guest
Posts: n/a
 
      02-05-2011
Tobias Blass <(E-Mail Removed)> writes:

> I'm just reading fetchmail source code and found the following lines
> /* env.c, line 37 */
> void envquery(int argc,char **argv)
> {
> /* ... */
> (void)argc;
> (void)argc;
> /*...*/
> }
>
> envquery is called (from main()) like this
>
> envquery(argc,argv);
>
> I don't really get the sense of these two (void)argc; . Does this have
> any special meaning or is it really "take the value of argc and ignore
> it"?


That's pretty much what it does. So does

argc;
argv;

with no casts but a compiler is more likely to complain about that and I
guess whole point is to suppress a warning about argc and argv being
unused. Guessing some more, I would suppose that envquery is passed
argc and argv because there might have been a plan to use them in the
future, or because some versions of the function do and some don't (if
there are conditionally compiled sections in the function for example).

--
Ben.
 
Reply With Quote
 
Tobias Blass
Guest
Posts: n/a
 
      02-05-2011


On Sun, 6 Feb 2011, Ian Collins wrote:

> On 02/ 6/11 11:29 AM, Ian Collins wrote:
>> On 02/ 6/11 11:02 AM, Tobias Blass wrote:
>>> Hi all,
>>> I'm just reading fetchmail source code and found the following lines
>>> /* env.c, line 37 */
>>> void envquery(int argc,char **argv)
>>> {
>>> /* ... */
>>> (void)argc;
>>> (void)argc;
>>> /*...*/
>>> }
>>>
>>> envquery is called (from main()) like this
>>>
>>> envquery(argc,argv);
>>>
>>> I don't really get the sense of these two (void)argc; . Does this have
>>> any special meaning or is it really "take the value of argc and ignore
>>> it"?

>>
>> Yes, probably to silence an over enthusiastic compiler of lint.

>
> Make that "compiler *or* lint".
>

But what should lint complain about, resp. why doesn't lint complain
any more if you add (void)argc?
 
Reply With Quote
 
Tobias Blass
Guest
Posts: n/a
 
      02-05-2011


On Sat, 5 Feb 2011, Ben Bacarisse wrote:

>Tobias Blass <(E-Mail Removed)> writes:
>
>> I'm just reading fetchmail source code and found the following lines
>> /* env.c, line 37 */
>> void envquery(int argc,char **argv)
>> {
>> /* ... */
>> (void)argc;
>> (void)argc;
>> /*...*/
>> }
>>
>> envquery is called (from main()) like this
>>
>> envquery(argc,argv);
>>
>> I don't really get the sense of these two (void)argc; . Does this have
>> any special meaning or is it really "take the value of argc and ignore
>> it"?

>
>That's pretty much what it does. So does
>
> argc;
> argv;
>
>with no casts but a compiler is more likely to complain about that and I
>guess whole point is to suppress a warning about argc and argv being
>unused. Guessing some more, I would suppose that envquery is passed
>argc and argv because there might have been a plan to use them in the
>future, or because some versions of the function do and some don't (if
>there are conditionally compiled sections in the function for example).
>
>--
>Ben.
>

You're right, it seems that argc is never used later in the function
(just argv). Thanks for your fast reply
(When I posted the other message with the question what lint should complain
about I haven't seen this reply yet. You can ignore it)
 
Reply With Quote
 
Johannes Schaub (litb)
Guest
Posts: n/a
 
      02-06-2011
Tobias Blass wrote:

> Hi all,
> I'm just reading fetchmail source code and found the following lines
> /* env.c, line 37 */
> void envquery(int argc,char **argv)
> {
> /* ... */
> (void)argc;
> (void)argc;
> /*...*/
> }
>
> envquery is called (from main()) like this
>
> envquery(argc,argv);
>
> I don't really get the sense of these two (void)argc; . Does this have
> any special meaning or is it really "take the value of argc and ignore
> it"?


Noone has yet pointed out that only the first (void)argc; really is useful.
The second (void)argc; is really without sense. I suspect that's a typo, and
the second one should be (void)argv;.
 
Reply With Quote
 
Tobias Blass
Guest
Posts: n/a
 
      02-06-2011


On Sun, 6 Feb 2011, Johannes Schaub (litb) wrote:

>Tobias Blass wrote:
>
>> Hi all,
>> I'm just reading fetchmail source code and found the following lines
>> /* env.c, line 37 */
>> void envquery(int argc,char **argv)
>> {
>> /* ... */
>> (void)argc;
>> (void)argc;
>> /*...*/
>> }
>>
>> envquery is called (from main()) like this
>>
>> envquery(argc,argv);
>>
>> I don't really get the sense of these two (void)argc; . Does this have
>> any special meaning or is it really "take the value of argc and ignore
>> it"?

>
>Noone has yet pointed out that only the first (void)argc; really is useful.
>The second (void)argc; is really without sense. I suspect that's a typo, and
>the second one should be (void)argv;.
>

This wouldn't make sense either, since argv is used in the function in every
case (not only in possible #ifdef branches or something). You can see it in the
fetchmail source code if you wannt to see it 8I don't want to post the entire
100 lines function here)
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-06-2011
Tobias Blass <(E-Mail Removed)> writes:
> On Sun, 6 Feb 2011, Johannes Schaub (litb) wrote:
>>Tobias Blass wrote:
>>
>>> Hi all,
>>> I'm just reading fetchmail source code and found the following lines
>>> /* env.c, line 37 */
>>> void envquery(int argc,char **argv)
>>> {
>>> /* ... */
>>> (void)argc;
>>> (void)argc;
>>> /*...*/
>>> }
>>>
>>> envquery is called (from main()) like this
>>>
>>> envquery(argc,argv);
>>>
>>> I don't really get the sense of these two (void)argc; . Does this have
>>> any special meaning or is it really "take the value of argc and ignore
>>> it"?

>>
>>Noone has yet pointed out that only the first (void)argc; really is useful.
>>The second (void)argc; is really without sense. I suspect that's a typo, and
>>the second one should be (void)argv;.
>>

> This wouldn't make sense either, since argv is used in the function in every
> case (not only in possible #ifdef branches or something). You can see it in the
> fetchmail source code if you wannt to see it 8I don't want to post the entire
> 100 lines function here)


So it's a (harmless) error in the fetchmail source. If neither argc nor
argv were used, it would make sense to have

(void)argc;
(void)argv;

Since argv is used but argc isn't, it would make sense to have:

(void)argc;

There's no particular reason for the compiler to warn about it, so it
was missed.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
My theory on why we have "senseless" wars ilyashambat@mailinator.com Digital Photography 90 06-09-2005 11:17 PM
Senseless rendering: Mac.Mozilla != Mac.Netscape6.01 ?!?! Roman =?ISO-8859-15?Q?Bl=F6th?= HTML 1 07-02-2003 10:23 AM



Advertisments