This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: How to force gcc warn the conditions which are true of false forever?
- From: Brian Dessent <brian at dessent dot net>
- To: Pan ruochen <panruochen at gmail dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Tue, 04 Nov 2008 05:18:27 -0800
- Subject: Re: How to force gcc warn the conditions which are true of false forever?
- References: <af0faace0811040336v669c6f5cla576a03562c3b004@mail.gmail.com>
- Reply-to: gcc-help at gcc dot gnu dot org
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