Re: intializing the variables and compling with optimization

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

 



J M Sharath Bharadwaj bharadwaj wrote:
> hi Andrew,
> 
> I was talking about warning option called -Wuninitialized
> Here in the below code, compiler gives warning like " might be used
> uninitialized in this function" for x ,
> {
>   int x;
>   switch (y)
>    {
>     case 1: x = 1;
>       break;
>     case 2: x = 4;
>       break;
>     case 3: x = 5;
>    }
>   foo (x);
> }
> 
> If the value code{y} is always 1, 2 or 3, then code{x} is
> always initialized, but GCC doesn't know this. So it emits a warning.
> 
> My question was, if I am going to initialize the variable x to some
> value. is that going to help for the compiler to perform better
> optimization, without giving ant warnings

Probably not.  As Robert William Fuller said, use a default case.

Andrew.

[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