Mail Archives: djgpp/2004/07/21/05:45:18
Sterten <sterten AT aol DOT com> wrote:
> I think I figured out where the problem is.
I don't think so.
> I have always been using things like R[99}={0}; thinking that all 99
> entries of the array are initialized with 0,
And they will be. Go look at things in the debugger if you don't
believe me.
Actually, since you define all your variables at file scope, so they're
all of static storage duration, they'll all be initialized to zero
even if you don't supply any initializer. I.e. in the case at hand, a
simple
int R[99];
would have worked just as well.
> but apparantly only the first value is zero while the others are
> undefined and (almost) unpredictable.
What makes you say that? What evidence do you have to support this?
It's actually much more likely that you're overrunning one of the other
arrays and thus stomping into the area allocated to R[].
Which brings me to one more issue with your sourcecode I wanted to
point out earlier, but didn't: it's full of statically sized arrays
[99] [999], [22], and so on, but you allow arbitrarily large
dimensions 'n' to be passed to the actual program. That's risky at
best, and may quite possibly lead to exactly the kind of problems
you're running into.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -