Mail Archives: djgpp/1997/10/06/04:31:53
Liche wrote:
>
> I use DJGPP v2.01, with RHIDE 1.4.
> When I compile this code:
> #include <iostream.h>
>
> short counter()
> {
> auto short count;
> count ++;
> cout << count << " ";
> return 0;
> }
>
> int main()
> {
> short i;
> for (i = 0; i < 10; i ++)
> counter();
> return 0;
> }
>
> This is displayed:
> 1 2 3 4 5 6 7 8 9 10
>
> This happens everytime. Shouldn't the values returned be random?
> If I change auto short count; with auto short count = 20; , however,
> this is displayed:
> 21 22 23 24 25 26 27 28 29 30
>
> Is this a problem with me, DJGPP, or RHIDE?
you.
the first one is not very surprising.
the values are not supposed to be random; they are just undefined; i.e.
the memory location is not initialized when the variable is created.
i don't understand the second case, are you saying that djgpp fails to
initialize count with 20 in the following function:
> short counter()
> {
> auto short count = 20;
> count ++;
> cout << count << " ";
> return 0;
> }
if you made this change, and you did not get 21 21 21 21 21 21 ... i
can't be 100% certain (i don't feel like booting back to dos right now)
but i seriously doubt you second claim.
--
----------------------------------------------------------------------
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 -