[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: huh???
From:       Thiago Macieira <thiago.macieira () kdemail ! net>
Date:       2004-04-28 15:37:23
Message-ID: 200404281237.23841.thiago.macieira () kdemail ! net
[Download RAW message or body]


George Staikos wrote:
>Out of curiousity, can anyone explain this code?  Thanks :)
>
>void KMdiMainFrm::removeFromActiveDockList(KMdiDockContainer* td) {
>  for (int i=0;i<4;i++) {
>    if (d->activeDockPriority[i]==td) {
>      // FIXME: HUH??  i2 is never used here, and this for() loop
> modifies the //        variable from the outer loop!!
>      for (int i2=i;i<3;i++)
>        d->activeDockPriority[i]=d->activeDockPriority[i+1];
>      d->activeDockPriority[3]=0;
>      break;
>    }
>  }
>}

i2 is indeed never used. It's useless there.

However, the code seems safe. It finds the first matching in 
activeDockPriority, then bumps up the priority for the rest of the 
elements (3 becomes 2, 2 becomes 1, and so forth).

Since there's a break inside the if, the code is safe to modify the 
outer loop variable.

-- 
  Thiago Macieira  -  Registered Linux user #65028
   thiago (AT) macieira (DOT) info
    ICQ UIN: 1967141   PGP/GPG: 0x6EF45358; fingerprint:
    E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358

[Attachment #3 (application/pgp-signature)]

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic