cppcheck encourages programmers to declare variables inside for loops, not so efficient. Some variables can be declared within the for loop initializer statement, but only one type can be declare there, so if that is taken, then there is nothing to do but keep the other variable scope as-is.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This has been discussed on stackoverflow already. For primitive types it is no problem to declare them inside the loop.
For classes it depends on whether instatiation or assignment is faster. So if you really depend on the performance, it should be measured which is faster.
Have you found some specific code where Cppcheck is always wrong? Could you post a reduced code example?
Do you think the description for this message should be further enhanced to warn that the performance might be influenced?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
cppcheck encourages programmers to declare variables inside for loops, not so efficient. Some variables can be declared within the for loop initializer statement, but only one type can be declare there, so if that is taken, then there is nothing to do but keep the other variable scope as-is.
This has been discussed on stackoverflow already. For primitive types it is no problem to declare them inside the loop.
For classes it depends on whether instatiation or assignment is faster. So if you really depend on the performance, it should be measured which is faster.
Have you found some specific code where Cppcheck is always wrong? Could you post a reduced code example?
Do you think the description for this message should be further enhanced to warn that the performance might be influenced?