From: Jeffrey Carter <spam@spam.com>
Subject: Re: windows ada compiler error
Date: Tue, 14 Oct 2003 20:42:56 GMT
Date: 2003-10-14T20:42:56+00:00 [thread overview]
Message-ID: <kdZib.1075$7a4.137@newsread4.news.pas.earthlink.net> (raw)
In-Reply-To: <vomtfia7418ob9@corp.supernews.com>
Andrew wrote:
> but I always get the
> raised ADA.IO_EXCEPTION.NAME_ERROR : s-fileio.adb:869
> error
That means there's a problem with your file name. Most likely, you're
trying to open a file that doesn't exist. Since you're creating the
file, you probably want to use Create rather than Open.
Your code is full of things that indicate you don't understand basic Ada
concepts. I'll try to point them out so you can learn about them.
I notice that the code has a number of initialized variables that you
never assign to. These are called constants, and should be declared as
such. For example,
> down: Integer:=10; -- down map
> acros: INTEGER:=10; -- across map
should probably be
Down : constant := 10;
Across : cosntant := 10;
> for i in 1..down loop
> for j in 1..acros loop
> map_array(i,j):='X';
> end loop;
> end loop;
You can create a literal for an entire array in Ada:
Map_Array := (others => (others => 'X') );
You don't need to assign element by element. In fact, you can do this
when you declare the object:
Map_Array : Map_Hold (1 .. Down, 1 .. Across) :=
(others => (others => 'X') );
When you do need to iterate over an array, you don't need to remember
what range you declared it with:
for I in Map_Array'range (1) loop
for J in Map_Array'range (2) loop
For a one-dimensional array, you can just use Name'range, without the "(1)".
> while FoundExit /= 1 loop
This indicates that you don't understand Booleans. You should have
Found_Exit : Boolean := False;
...
loop
exit when Found_Exit;
...
Found_Exit := True;
A loop with an exit reads better and is easier to understand than
while not Found_Exit loop
> Open (map_file, out_FILE, "Map");
This fails if a file name "Map" doesn't already exist.
> if IS_OPEN(map_file) then
If Open fails, an exception is raised (as you have discovered).
Therefore, this test will always be true if you get here. You don't need
it and it complicates your code. Add an exception handler to deal with
the exceptional case.
> else
> Put_Line("Map file didn't open .. Killing Program");
> end if;
[else to the if above] You can never get here. And if you did, you don't
kill the program anyway.
Finally, your indentation and capitalization seem random. Regular
indentation helps the reader see the structure of the program. Regular
capitalization and putting underlines between words in identifiers makes
your code easier to read.
--
Jeff Carter
"Death awaits you all, with nasty, big, pointy teeth!"
Monty Python & the Holy Grail
20
prev parent reply other threads:[~2003-10-14 20:42 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-10-14 4:05 windows ada compiler error Andrew
2003-10-14 5:19 ` tmoran
2003-10-14 15:29 ` Andrew
2003-10-14 15:35 ` Andrew
2003-10-14 16:17 ` Stephen Leake
2003-10-14 19:06 ` Andrew
2003-10-14 20:42 ` Jeffrey Carter [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox