intializing the variables and compling with optimization
J M Sharath Bharadwaj bharadwaj
sharathjm.bharadwaj@gmail.com
Sat Jul 12 17:11:00 GMT 2008
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
Sharath.
On Fri, Jul 11, 2008 at 7:19 PM, Andrew Haley <aph@redhat.com> wrote:
> J M Sharath Bharadwaj bharadwaj wrote:
>>
>> hi All,
>>
>> Is GCC going to perform a better optimization, if I am going to
>> initialize the variable explicitly. I am asking this because I was
>> reading the GCC online doc for warning options like as in
>> http://www.cs.cmu.edu/cgi-bin/info2www?(gcc.info)Warning%20Options
>
> This is a strange question.
>
> If you read an uninitialized variable your program contains undefined
> behaviour, and optimization is going to be the least of your problems.
> If you don't read from an uninitialized variable it doesn't matter.
>
> Andrew.
>
More information about the Gcc-help
mailing list