Mail Archives: djgpp/2002/03/31/12:26:57
> 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 -