delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/05/21:16:34

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bug in DJGPP?
Date: Sun, 05 Oct 1997 20:39:57 -0400
Organization: Cornell University http://www.cornell.edu
Lines: 32
Sender: asu1 AT cornell DOT edu (Verified)
Message-ID: <3438335D.BD87B172@cornell.edu>
References: <3437974D DOT E060AD2A AT mail DOT linkease DOT com DOT tw> <3437987F DOT 2592977D AT mail DOT linkease DOT com DOT tw> <343807DE DOT 583B AT cam DOT org>
Reply-To: asu1 AT cornell DOT edu
NNTP-Posting-Host: cu-dialup-0028.cit.cornell.edu
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Vic wrote:
> 
> Liche wrote:
> >
> > Liche wrote:
> >
> > I am sorry, it displays 21 ten times if I use auto short count = 20;,
> > instead of 21 22 23...
> > Anyways, this is still a weird result.  It seems that if I don't
> > initialize a variable to a value then it is static, even if i use auto
> > short count; ......
> > Can anybody else reproduce this?
> yes, me. And indeed I find it weird. Cause if I say something like 
> auto int x; then I print the value of X it will be something random.

it is absolutely not weird. 'auto' is not a synonym for 'random variable
generator'. the whole point is the value of a non-static local variable
is not initialized, it is undefined. undefined does not mean every time
the variable is created, the compiler is going to spend extra effort
making sure that the value it points to contains some 'random' (whatever
you guys are using it to mean) value. the variable is not initialized.
the value it holds is undefined. therefore, it can be anything including
your birthday.

-- 
----------------------------------------------------------------------
A. Sinan Unur
Department of Policy Analysis and Management, College of Human Ecology,
Cornell University, Ithaca, NY 14853, USA

mailto:sinan DOT unur AT cornell DOT edu
http://www.people.cornell.edu/pages/asu1/

- Raw text -


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