X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f Message-ID: <20040727195006.4584.qmail@web50704.mail.yahoo.com> Date: Tue, 27 Jul 2004 12:50:06 -0700 (PDT) From: Lets Go Canes Subject: Re: assembly code of the "strange error" - program To: djgpp AT delorie DOT com In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii 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 --- Paul Wilkins wrote: > Sterten wrote: > > > Paul Wilkins wrote: > > >int R[99]; // won't be initialised and will have different values > > > > I was told, they were set to zero ? > > My C manual says otherwise. > > "If you do not initialize any elements of an array, the compiler > will NOT implicitly set all elements to 0. C does not specify > that > the compiler automatically initialize all variables and arrays. > The > values of an array are undetermined unless you initialize it > either in the definition statement or by explicit assignment." > > There may be a compiler that does initialise them to 0, but you can't > > guarantee that every compiler will do so, so play it safe and work on > > the worst case scenario. Generically speaking (i.e., not DJGPP-specific), as a practical matter, it will depend on where the data is located in memory. If the array is allocated by the loader at run-time, *most* systems will provide memory that has been pre-initialized with 0s. Otherwise it depends. Either way you should not assume that it will pre-initialized, and initialize it yourself. Speaking of implementation issues, FWIW my experience is that when initializing an array at execution, the choice between a "for" loop and "memset" should almost *always* be "for" - if it is more efficient to use "memset", the compiler will usually figure it out during the optimization phase and replace your "for" loop with memset (or the assembler equivalent). I've never checked to see what gcc does, but I would be surprised if it didn't behave similarly. ===== -------------- Lets Go Canes! __________________________________ Do you Yahoo!? Yahoo! Mail - 50x more storage than other providers! http://promotions.yahoo.com/new_mail