Menu

Overeager scope reduction

mcandre
2019-01-20
2019-01-22
  • mcandre

    mcandre - 2019-01-20

    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.

     
  • versat

    versat - 2019-01-22

    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?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.