mardi 28 mars 2017

will g++ compiler automatically remove const temporary variables?

very often we have something like this in our code, which is difficult to read

tryYourMagic(a, b,c, someVeryComplicatedFunction(param1, param2, ... paramN));

I usually turn this into 2 lines:

const double temp = someVeryComplicatedFunction(param1, param2, ... paramN);
tryYourMagic(a, b,c, temp);

I had thought g++ would automatically remove this temp variable so the first and second code block would look the same in binary code.

But I am not really sure about this, can anyone give any clarification here?

Thanks

Aucun commentaire:

Enregistrer un commentaire