From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: [Beginner Problem] Varibles not getting assigned correctly
Date: Fri, 11 Jan 2008 10:01:17 +0200
Date: 2008-01-11T10:01:17+02:00 [thread overview]
Message-ID: <47871f8f$0$21897$4f793bc4@news.tdc.fi> (raw)
In-Reply-To: <13oe10uh39g0v85@corp.supernews.com>
Shane Smith wrote:
> Hi all,
>
> I'm trying to write a simple program (that manacla game), I've
> encountered a problem where the variables that are used in a nested
> procedure can't be assigned a value. I'm using GNAT 4.1.2 on Linux.
I think your conclusion ("can't be assigned a value") is too
strong; what you really observed is "gdb displays an unexpected value".
I occasionally get weird values from gdb (which I seldom use,
though) from Ada programs, where a Text_IO.Put at the same place
shows the correct, expected value.
> type arr_point is access pits;
> board : arr_point;
It's not necessarily relevant, but I'm curious why you use an
access type for the board. Are there several boards? (I don't know
this game.)
By the way, even with an access type, you don't need the ".all"
below, where you write board.all(2 .. 7), you can write just
board(2 .. 7). The ".all" is implied when you index an array or
take a slice of it.
> procedure Status (Player : in integer)
> is
>
> begin
> -- Check if 'playing pits' are empty, if not exit
> while board.all(2 .. 7) = (0,0,0,0,0,0) or board.all(9 .. 14) =
> (0,0,0,0,0,0) loop
Why are you looping here? The only thing that may change in the
loop is the Winner variable, so the loop either never starts, or
exits in the first iteration, or never exits.
> if Player = 1 then
> if board.all(2 .. 7) = (0,0,0,0,0,0) then
> Winner := 1;
If this happens, the loop gets stuck and never exits.
> else exit;
> end if;
> else
> if board.all(9 .. 14) = (0,0,0,0,0,0) then
> Winner := 2;
Same here.
> else exit;
> end if;
> end if;
> end loop;
> end Status;
>
> In gdb 'p winner' gives "$14 = 7270388".
At what point in the program did you give that gdb command? That
is, where did you break the program's execution?
If I had this problem I would first use Text_IO, not gdb, to print
out the values of the variables. If you do that, and you still get
the wrong value, perhaps you could show a bit more of the program
in your nest posting.
HTH
--
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
. @ .
next prev parent reply other threads:[~2008-01-11 8:01 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-11 5:52 [Beginner Problem] Varibles not getting assigned correctly Shane Smith
2008-01-11 8:01 ` Niklas Holsti [this message]
2008-01-11 10:46 ` Peter Hermann
2008-01-11 17:51 ` Jeffrey R. Carter
2008-01-12 3:00 ` Steve
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox