Reputation: 417
In my code I have
switch (cd->op)
{
...
}
and I'm wondering whether I should do
CalcWizConsts::eqOps thisOp = cd->op;
switch (thisOp)
{
...
}
Upvotes: 1
Views: 94
Reputation: 3821
The argument to switch
will only be evaluated once, so there is no need to store it in a temporary first. There is no performance difference, and you don't have to worry about changing the value in one of the case
clauses either. The only reason I can think of for assigning to a variable first is to make the code more readable, if the expression is lengthy.
Upvotes: 8