senseless statement?

T

Tobias Blass

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"?
 
I

Ian Collins

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.
 
I

Ike Naar

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'.
 
B

Ben Bacarisse

Tobias Blass said:
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).
 
T

Tobias Blass

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).
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)
 
J

Johannes Schaub (litb)

Tobias said:
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;.
 
T

Tobias Blass

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)
 
K

Keith Thompson

Tobias Blass said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top