Date: Sun, 9 Apr 2000 08:57:26 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp AT delorie DOT com Subject: Re: bug? In-Reply-To: <20000408155631.7966.qmail@hotmail.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Note-from-DJ: This may be spam Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Sat, 8 Apr 2000, Fredrik Olsson wrote: > Problem 1: > When u_RemoveFromSolid (int id) is called from > u_AddToSpawnList (int id), the variable "int i" is changed. > > - I have debugged the code and I found that > "int i" is changed when calling u_RemoveFromSolid() > from u_AddToSpawnList(), on that exact line. [snip] > void u_RemoveFromSolid (int id) { > int ai=0, removed; > > > for (ai=0;ai if (solid[ai] == id) > { > > // remove unit > solid[ai] = 0; > unit[id]->tables = unit[id]->tables & ~T_SOLID; > removed = ai; > > > // resort list > > for (i=MAXUNITS-1;i>removed;i--) > if (solid[i] != 0) { > solid[removed] = solid[i]; > solid[i] = 0; > return; > } > > > return; > > } This function uses the variable i, but it is not declared in this function. Where is i declared? Is this the exact code you were running? > // at this time i == 0 > // after the next line is run "int i" is changed. > > u_RemoveFromSolid (id); > > // at this time i == 427272 How are the arrays solid[] and unit[] declared? In the function u_RemoveFromSolid you seem to rely on these two arrays being declared with dimension MAXUNITS. If one of them has less elements, you are writing past the end of the array, which can cause otehr variables be overwritten. > 2: > --Could not debug some variables, "not availuable" > -still they can hold values: > > int a[10], b; > > b = 22; > a[0] = b; > > (when evaluating "int a" it is 22) This is normal: GCC puts some of the variables in registers, or even optimizes them out of existence, if they aren't used.