# Can someone explain to me

• 06-22-2005
rEtard
Can someone explain to me
Code:

```void CalculateMousePoint(int MaxCount,int minX,int minY,int MouseX,int MouseY) {         int i=0; // for loop         int noteWidth = 54;         int noteHeight = 50;         static int maxX;         static int maxY;         while(i<MaxCount)         {                 maxX = minX + noteWidth;                 maxY = minY + noteHeight;                 // check if mouse is within any note bitmaps                 if ( MouseX > minX && MouseX < maxX && MouseY > minY && MouseY < maxY )                 {                         Call();                         i = MaxCount;                 }                 else if ( maxX >= 307 )                 {                         minX = 125;                         minY += noteHeight + 20;                         i++;                         // pls think of a loop to solve the problem                         // this is for checking and increment max n min values                 }                 else                 {                         minX += noteWidth + 20;                         i++;                 }         } }```
alrite, i keep it short, this function is for looping through the coordinates of known starting X and Y axis, incrementing X most of the time and when X is at the max of Client area which is around 307, it will reset X to 125 and Y will increase. This function is used in WM_LBUTTONDOWN to correctly pinpoint whether an icon was clicked. Ok, here cums the problem.
i started this function by declaring the variables as normal int maxX,maxY and the loop failed and even freeze when it reaches if(maxX >= 307), i narrowed the search and found the culprit was minY += iconHeight + 20; i figured for almost 2 days where did i do wrong and around 5 mins earlier, i added static into my variables and the loop worked, but the funny thing is maxX do not require static and it still worked ?!?!
Can someone explain to me how does the static cum into place. Static is mainly used to retain the value within the variable but why doesn't maxX require it ???
• 06-22-2005
Salem
The short answer, in bug-free code, it should make no difference at all.
All that making it static does for you at the moment is put it in a different part of memory.

Most likely, if you debug it carefully, you'll see your variable changing value when you least expect it.
My idea is that there is a buffer overrun in some other function, and here is where you get to notice it. Rearranging the code rearranges the bug (so it doesn't happen here), but that's not to say that the bug has been fixed, or that something else unexpected won't happen somewhere else.