Re: How to force gcc warn the conditions which are true of false forever?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Pan ruochen wrote:

> How should I do if I do want gcc to give warnings about these code,
> since in most cases

Use -Wunreachable-code and enable optimization.

Nicholas Sherlock wrote:

> Then what of usages like this?
> 
> #define DEBUG_MODE 0
> 
> if (id<0 && DEBUG_MODE) {
>     printf("Failed.\n");
>     return;
> }
> 
> This expression can never be satisfied either.

This is exactly why the warning is not enabled with -Wall, to quote the
fine manual:

> This option is not made part of -Wall because in a debugging version of 
> a program there is often substantial code which checks correct 
> functioning of the program and is, hopefully, unreachable because the 
> program does work. Another common use of unreachable code is to provide 
> behavior which is selectable at compile-time. 

<http://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wunreachable_002dcode-432>

Brian

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux