Mail Archives: djgpp/2000/04/09/03:10:32
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<MAXUNITS;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.
- Raw text -