delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2004/07/21/05:45:18

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: Hans-Bernhard Broeker <broeker AT physik DOT rwth-aachen DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: strange error
Date: 21 Jul 2004 09:38:20 GMT
Lines: 39
Message-ID: <2m6rscFjl139U3@uni-berlin.de>
References: <20040721024308 DOT 25600 DOT 00002362 AT mb-m29 DOT aol DOT com> <20040721040948 DOT 06719 DOT 00001805 AT mb-m13 DOT aol DOT com>
X-Trace: news.uni-berlin.de bD8zc0dc/OTPi+EhEcxwtAzA5ZyR6diliKsB9/iN5TLQIoHIAREHsX9YRl
X-Orig-Path: not-for-mail
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019