www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/03/31/12:26:57

X-Authentication-Warning: delorie.com: mailnull set sender to djgpp-bounces using -f
To: Dong Soo Kim <dsk666 AT cse DOT unsw DOT edu DOT au>
CC: djgpp AT delorie DOT com
In-reply-to:
<Pine DOT GSO DOT 4 DOT 44 DOT 0203311822550 DOT 17216-100000 AT hummel DOT orchestra DOT cse DOT unsw DOT EDU DOT AU>
(message from Dong Soo Kim on Sun, 31 Mar 2002 18:24:52 +1000 (EST))
Subject: Re: g++ Warnings
References: <Pine DOT GSO DOT 4 DOT 44 DOT 0203311822550 DOT 17216-100000 AT hummel DOT orchestra DOT cse DOT unsw DOT EDU DOT AU>
Message-Id: <E16rj4a-0003CG-00@fencepost.gnu.org>
From: Eli Zaretskii <eliz AT gnu DOT org>
Date: Sun, 31 Mar 2002 12:24:56 -0500
Reply-To: djgpp AT delorie DOT com

> From: Dong Soo Kim <dsk666 AT cse DOT unsw DOT edu DOT au>
> Date: Sun, 31 Mar 2002 18:24:52 +1000 (EST)
> 
> > It would be a very Bad Idea (tm) for GCC to flag those cases, since
> > they are widely used to shut up compiler warnings about variables
> > which the compiler things are used before they are initialized.
> > (Compilers can err about this because they don't understand what
> > range of values can certain variables have, and thus don't know what
> > conditions could fire under what circumstances.)
> 
> out of curiosity, could you give some examples of occasions you'd need to
> use that technique?

Here's one trivial example (I didn't actually try to compile it with
"-Wall", so it might be that latest compilers are smarter than I
think; but you get the idea):

 int foo (int arg)
 {
   int i;

   if (arg > 5)
     i = arg * 2;
   if (arg > 6)
     {
       i += 8;
       return i;
     }
   return arg + 5;
 }

Here, the second if clause is never entered unless arg > 5, which
means i is initialized.  But the compiler might not know that, so it
will complain.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019