Re: best way to suppress "unused" warning?

Discussion in 'C Programming' started by Antoninus Twink, Apr 25, 2008.

  1. On 25 Apr 2008 at 1:24, Richard Heathfield wrote:
    > Lots of people use (void)data for this, and it's just as good a way as
    > any of those you mention


    Obfuscating your code to pacify your compiler or lint smacks to me of
    letting the tail wag the dog.
     
    Antoninus Twink, Apr 25, 2008
    #1
    1. Advertising

  2. Antoninus Twink wrote:
    > On 25 Apr 2008 at 1:24, Richard Heathfield wrote:
    >> Lots of people use (void)data for this, and it's just as good a way
    >> as any of those you mention

    >
    > Obfuscating your code to pacify your compiler or lint smacks to me of
    > letting the tail wag the dog.

    In real life there may be coding standards that demand for this.

    At one company I used to work for it was mandatory to use "-Wall -Werror",
    or something eqivalent and all new code and on all older code once it got
    touched.

    It was a pain in the proverbian, but lead to much better code and lots of
    yet unexplained faults mysteriously disappaered...

    Bye, Jojo
     
    Joachim Schmitz, Apr 25, 2008
    #2
    1. Advertising

  3. In article <>,
    Antoninus Twink <> wrote:

    >> Lots of people use (void)data for this, and it's just as good a way as
    >> any of those you mention


    >Obfuscating your code to pacify your compiler or lint smacks to me of
    >letting the tail wag the dog.


    It's a difficult balance to strike. I have at least once missed an
    important warning because it was surrounded by unimportant ones that
    I was expecting.

    -- Richard



    --
    :wq
     
    Richard Tobin, Apr 25, 2008
    #3
  4. Joachim Schmitz wrote:
    > Antoninus Twink wrote:
    > > Richard Heathfield wrote:
    > > > Lots of people use (void)data for this, and it's just as good
    > > > a way as any of those you mention

    > >
    > > Obfuscating your code to pacify your compiler or lint smacks
    > > to me of letting the tail wag the dog.

    >
    > In real life there may be coding standards that demand for this.


    Of course, tail wagging the dog is standard policy in many
    avenues of life. That doesn't mean it's sensible.

    > At one company I used to work for it was mandatory to use
    > "-Wall -Werror", or something eqivalent and all new code and
    > on all older code once it got touched.


    So if the compiler ever get's upgraded, you may have to 'correct'
    thousands of lines of perfectly correct code because the compiler
    writers decided to add another warning? Brilliant.

    Did you have to rewrite third party library sources as well?

    > It was a pain in the proverbian, but lead to much better code


    Warning free is not a measure of 'better'. But I'm in a minority
    on that.

    > and lots of yet unexplained faults mysteriously disappaered...


    I'm sure it also lead to the appearance (albeit rare) of
    mysterious faults that went undiscovered for some time until a
    critical moment precisely because all the programmers have
    been conditioned to write code that eludes diagnostics and
    static analysis.

    Ever heard the term superbugs. ;-)

    --
    Peter
     
    Peter Nilsson, Apr 29, 2008
    #4
  5. "Peter Nilsson" <> schrieb im Newsbeitrag
    news:...
    > Joachim Schmitz wrote:
    >> Antoninus Twink wrote:
    >> > Richard Heathfield wrote:
    >> > > Lots of people use (void)data for this, and it's just as good
    >> > > a way as any of those you mention
    >> >
    >> > Obfuscating your code to pacify your compiler or lint smacks
    >> > to me of letting the tail wag the dog.

    >>
    >> In real life there may be coding standards that demand for this.

    >
    > Of course, tail wagging the dog is standard policy in many
    > avenues of life. That doesn't mean it's sensible.
    >
    >> At one company I used to work for it was mandatory to use
    >> "-Wall -Werror", or something eqivalent and all new code and
    >> on all older code once it got touched.

    >
    > So if the compiler ever get's upgraded, you may have to 'correct'
    > thousands of lines of perfectly correct code because the compiler
    > writers decided to add another warning? Brilliant.

    The vast majority was stuff like comment inside comment, steming from the
    function headers like this:

    /***********
    /*
    /* some text describing the function
    */

    Once they've been fixed, the real warnings became visible.
    Statement with no effect (e.g. from ; after while())
    conversion of <type> to <type> without a case (and no the fix was not to add
    the cast)
    implicit declaration of <function>
    unused variable

    etc.

    Newer compiler versions didn't create many new warnings, so that wasn't much
    of an issue,
    but porting to a different platform (and compiler) then produced a new and
    extensive set of warnings, the majority usefull and correct ones.

    > Did you have to rewrite third party library sources as well?

    There were none, fortunatly.

    >> It was a pain in the proverbian, but lead to much better code

    >
    > Warning free is not a measure of 'better'. But I'm in a minority
    > on that.
    >
    >> and lots of yet unexplained faults mysteriously disappaered...

    One example was lots of warnigs about unused variables. We removed these and
    the code didn't crash anymore. Later we learned that that particular
    compiler's optimizer had a problem with unused vairables, resulting in bad
    code.
    OK, in this case a compiler upgrade would have fixed it too, but at that
    time we a) didn't know and b) the fixed compiler wasn't available.

    > I'm sure it also lead to the appearance (albeit rare) of
    > mysterious faults that went undiscovered for some time until a
    > critical moment precisely because all the programmers have
    > been conditioned to write code that eludes diagnostics and
    > static analysis.

    I'm not aware of any

    Bye, Jojo
     
    Joachim Schmitz, Apr 29, 2008
    #5
  6. "Peter Nilsson" <> schrieb im Newsbeitrag
    news:...
    > Joachim Schmitz wrote:

    <snip>
    >> (removing the warnings) was a pain in the proverbian, but lead to much
    >> better code

    >
    > Warning free is not a measure of 'better'. But I'm in a minority
    > on that.

    It was not (only) better because of the lack of warnings, but (mainly) due
    to the numbers of bugs we spotted and removed in the due course of
    investigating and eliminating the warnings.

    Bye, Jojo
     
    Joachim Schmitz, Apr 29, 2008
    #6
  7. Antoninus Twink

    Ian Collins Guest

    Joachim Schmitz wrote:
    > Antoninus Twink wrote:
    >> On 25 Apr 2008 at 1:24, Richard Heathfield wrote:
    >>> Lots of people use (void)data for this, and it's just as good a way
    >>> as any of those you mention

    >> Obfuscating your code to pacify your compiler or lint smacks to me of
    >> letting the tail wag the dog.

    > In real life there may be coding standards that demand for this.
    >

    Adding unnamed parameters would fix this case and break nothing. But I
    guess there little chance of such a simple change making its way into
    the standard.

    --
    Ian Collins.
     
    Ian Collins, Apr 29, 2008
    #7
    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. Christian Seberino
    Replies:
    0
    Views:
    356
    Christian Seberino
    Oct 21, 2003
  2. Ian Bicking
    Replies:
    0
    Views:
    391
    Ian Bicking
    Oct 22, 2003
  3. Replies:
    3
    Views:
    331
    Malcolm McLean
    Nov 28, 2007
  4. Replies:
    0
    Views:
    477
  5. mathog
    Replies:
    47
    Views:
    512
    Tim Rentsch
    Jun 12, 2014
Loading...

Share This Page