[cmake-developers] [ctest][coding-style] for-loop local variable usage

Maik Beckmann beckmann.maik at googlemail.com
Sat May 31 07:29:32 EDT 2008


Hello,

Call me paranoid, but I've been bitten by non local loop variables several 
times and thus I get nervous when seeing something like this
{{{
  int cc; // <- declared here
  values.resize(last);
  for ( cc = 0; cc < last; ++ cc ) // <- cc used here
    {
    values[cc] = 0;
    }

  for(size_t i=0; i < args.size(); ++i) // how i like it
    {
    if ( state > 0 && state < last )
      {
      values[state] = args[i].c_str();
      cmCTestLog(this->CTest, DEBUG, "Set " << strings[state] << " to "
        << args[i].c_str() << std::endl);
      state = 0;
      }
    else
      {
      bool found = false;
      for ( cc = 0; cc < last; ++ cc )  // <- cc used again
        {
        if ( strings[cc] && args[i] == strings[cc] )
...
}}}
This really alarm my spider sensors.  

Sometimes variables having a higher scope are necessary , i.e. when doing some 
fancy search algorithms.  But if isn't need I like to patch it aways to avoid 
upcoming trouble when modifying such code.

Am I to picky?


-- Maik



More information about the cmake-developers mailing list