senseless statement?

Discussion in 'C Programming' started by Tobias Blass, Feb 5, 2011.

  1. Tobias Blass

    Tobias Blass Guest

    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"?
     
    Tobias Blass, Feb 5, 2011
    #1
    1. Advertising

  2. Tobias Blass

    Ian Collins Guest

    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
     
    Ian Collins, Feb 5, 2011
    #2
    1. Advertising

  3. Tobias Blass

    Ian Collins Guest

    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
     
    Ian Collins, Feb 5, 2011
    #3
  4. Tobias Blass

    Ike Naar Guest

    On 2011-02-05, Tobias Blass <> 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'.
     
    Ike Naar, Feb 5, 2011
    #4
  5. Tobias Blass <> 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.
     
    Ben Bacarisse, Feb 5, 2011
    #5
  6. Tobias Blass

    Tobias Blass Guest

    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?
     
    Tobias Blass, Feb 5, 2011
    #6
  7. Tobias Blass

    Tobias Blass Guest

    On Sat, 5 Feb 2011, Ben Bacarisse wrote:

    >Tobias Blass <> 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)
     
    Tobias Blass, Feb 5, 2011
    #7
  8. 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;.
     
    Johannes Schaub (litb), Feb 6, 2011
    #8
  9. Tobias Blass

    Tobias Blass Guest

    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)
     
    Tobias Blass, Feb 6, 2011
    #9
  10. Tobias Blass <> 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.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
     
    Keith Thompson, Feb 6, 2011
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    3
    Views:
    838
  2. Jay McGavren
    Replies:
    11
    Views:
    1,187
    Alan Krueger
    Jan 16, 2006
  3. Roman =?ISO-8859-15?Q?Bl=F6th?=

    Senseless rendering: Mac.Mozilla != Mac.Netscape6.01 ?!?!

    Roman =?ISO-8859-15?Q?Bl=F6th?=, Jul 2, 2003, in forum: HTML
    Replies:
    1
    Views:
    1,026
    Steve Pugh
    Jul 2, 2003
  4. tedsuzman
    Replies:
    2
    Views:
    7,167
    Michel Claveau, résurectionné d'outre-bombe inform
    Jul 21, 2004
  5. Ted
    Replies:
    1
    Views:
    497
    Duncan Booth
    Jul 22, 2004
Loading...

Share This Page