Optimization of variables

Marcus Clyne maccaday@gmail.com
Wed Feb 3 17:42:00 GMT 2010


Hi,

Will the following C code :

int y;
{
    int   x1, x2;

    x1 = 3;
    x2 = 4;

    y = x1 + x2;
}

be compiled as :

int y = 7;

automatically, without creating the extra variables on the stack and 
performing the addition calculation?

Is this true of all code, or only with certain optimizations (e.g. -O2).

Thanks,

Marcus.



More information about the Gcc-help mailing list