mercredi 7 avril 2021

Is variable defined out of scope Optimized?

So, some may agree that (code 1):

void func()
{
    int a, b;
    {
        //Do something with a and b
    }
}

Looks better (or is a better practice) than (code 2):

void func()
{
    int a;
    {
        int b;
        //Do something with a and b
    }
}

Also, than this (code 3):

void func()
{
    {
        int a, b;
        //Do something with a and b
    }
}

If there are no redeclarations of a or b are these codes equivalent? will the compiler optimize this?

Aucun commentaire:

Enregistrer un commentaire