On 2006-03-21, David Brown <da...@westcontrol.com> wrote:

> I know this is slightly off topic...
>
> I also compile my code with a range of warnings enabled (including -W
> or -Wextra, depending on gcc version), at attempt to eliminate all warnings
> in the code.  But one that I never manage to completely eridicate is if I
> have "-Wunreachable-code" enabled.  

I rarely turn that one on.  There are too many times when I
have intentionally unreachable code that I'm expecting/allowing
the compiler to optimize away.  (Someday I'll probably get
burned by that, but it hasn't happened yet.) Most of the time
it seems the code I work on needs to be built a couple
different ways with different "optional" features enabled.

I don't like simply #if'ing out chunks of code, because then
the compiler won't check the "unused" code.  When I used to #if
out optional features, some rarely built optional feature would
always fail to build correctly the next time I try to build it.  

In order to prevent me from making changes that will obviously
break options that aren't enabled I now tend to do something
like this:

#define OptionalFeatureEnabled 0

[...]

  if (OptionalFeatureEnabled)
    {
      optinal code here that doesn't get included
      in output binary but gets checked by the compiler
      every build anyway.      
    }    

That also makes it trivial to change the "option" from a
compile-time selection to a run-time selection -- which seems
to happen now and then.
    
> This is normally a very useful warning (it will catch code
> such as "if (x = 0) ... "), but when combined with
> optimisation can give spurious warnings after combining "if"
> or "switch" branches.  Have you any ideas how to keep the real
> warnings without getting the spurious ones?

Not really.  There's __attribute__((unused)) to disable
warnings about functions and variables that you want compiled
even though they're not used (as far as the compiler can tell),
but that doesn't help when there are cases or if/else clauses
that aren't reachable and you actually want it that way.

-- 
Grant Edwards                   grante             Yow!  .. Everything
                                  at               is....FLIPPING AROUND!!
                               visi.com            


Reply via email to