In C++, does a mathematical declaration in a constant variable initialization costs some extra processing? Or modern compilers would automatically put the result of the mathematical calculation inside the variable when creating the .exe file?
So e.g.:
MyClass::MyClass()
{
const qint32 defaultX = 20;
poButton1 = new PushButton(this);
poButton1->move(defaultX,20);
poButton1 = new PushButton(this);
poButton1->move(defaultX,80);
//...
}
is a example of a code that uses a constant variable (defaultX) across a method usage (the constructor in this case). Now sometimes it's better for the developer to tell where the value came from:
MyClass::MyClass()
{
const qint32 defaultX = 800/2 - 244 + 12 + 32 - 180; //just an example!
poButton1 = new PushButton(this);
poButton1->move(defaultX,20);
poButton1 = new PushButton(this);
poButton1->move(defaultX,80);
//...
}
Of course he could just put that inside a comment, but let's suppose he wants to do it this way (e.g.: he is dumb). The question would then be: when a object of that class is being initialized, does that whole mathematical expression is calculated (costing extra processing) or when the .exe is created by modern compilers it already contains the optimized code seen in the first MyClass code?