comp.lang.ada
 help / color / mirror / Atom feed
* New to Ada, why these warning messages?
@ 2016-01-01  2:19 Dale Dellutri
  2016-01-01  2:47 ` David Botton
                   ` (3 more replies)
  0 siblings, 4 replies; 26+ messages in thread
From: Dale Dellutri @ 2016-01-01  2:19 UTC (permalink / raw)


I'm trying to compile and run the following program:
-- from: http://sandbox.mc.edu/~bennet/ada/examples/arr2_adb.html
-- Array aggregates.  Array aggregates are essentially constants of
-- array type.  They can be used either for initialization or in
-- assignment statements.
--
with Gnat.Io; use Gnat.Io;
procedure Gnatarr2 is
   -- Just some values to play with, along with a conversion array.
   type Paint is (Red, Green, Yellow, Blue, Pink, Orange, Mauve,
                  Cherry, Indigo, Brown);
   PNames: array(Paint) of String(1..6) :=
     ("Red   ", "Green ", "Yellow", "Blue  ", "Pink  ", "Orange", 
"Mauve ",
      "Cherry", "Indigo", "Brown ");

   -- The type of an array of paints, along with its size.
   N: constant := 8;
   type AType is array(Integer range 1..N) of Paint;

   -- Some Paint arrays.  The first one is initialized with a list
   -- of colors.
   A: AType := (Red, Red, Pink, Blue, Orange, Cherry, Indigo, Indigo);
   B, C: AType;

   I: Integer;          -- Loop index.

begin

   -- Use positions to set varioius values in various places.
   B := (5 => Green, 2 => Orange, 6..8 => Indigo, 1|3|4 => Brown);

   -- Set the entire array to Blue.
   C := (AType'First .. AType'Last => Blue);

   -- Print the position numbers, spaced out to align with the
   -- the printouts of each of the arrays below.
   for I in 1..N loop
      Put("  ");
      Put(I);
      Put("    ");
   end loop;
   New_Line;

   -- Print out the contents of each of A, B, and C.
   for I in 1..N loop
      Put(PNames(A(I)) & " ");
   end loop;
   New_Line;

   for I in 1..N loop
      Put(PNames(B(I)) & " ");
   end loop;
   New_Line;

   for I in 1..N loop
      Put(PNames(C(I)) & " ");
   end loop;
   New_Line;
end Gnatarr2;

I'm using gcc-gnat on Fedora 22 (I changed the name of
the file from arr2.adb to gnatarr2.adb and also the name
of the unit to Gnatarr2):

$ gnatmake src/gnatarr2.adb -o bin/gnatarr2
gcc -c -Isrc/ -I- src/gnatarr2.adb
gnatarr2.adb:24:04: warning: variable "I" is never read and never 
assigned
gnatarr2.adb:54:08: warning: for loop implicitly declares loop 
variable
gnatarr2.adb:54:08: warning: declaration hides "I" declared at line 24
gnatbind -x gnatarr2.ali
gnatlink gnatarr2.ali -o bin/gnatarr2

Of course, these are only warnings, and the unit compiles and runs.

If I comment out the defintion of I: Integer;, I get:

$ gnatmake src/gnatarr2.adb -o bin/gnatarr2
gcc -c -Isrc/ -I- src/gnatarr2.adb
gnatbind -x gnatarr2.ali
gnatlink gnatarr2.ali -o bin/gnatarr2

In this case, I assume it's using an implicit defintion of I.

But I do not understand the warning messages.  What's wrong with
the definition of I: Integer; on line 24?

-- 
Dale Dellutri <daQQQle@panQQQix.com> (lose the Q's)

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2016-01-03 19:05 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-01  2:19 New to Ada, why these warning messages? Dale Dellutri
2016-01-01  2:47 ` David Botton
2016-01-01  5:54 ` Jeffrey R. Carter
2016-01-01 21:18   ` Bob Duff
2016-01-01 17:30 ` Dennis Lee Bieber
2016-01-01 20:20 ` Dale Dellutri
2016-01-01 21:24   ` Bob Duff
2016-01-01 21:54     ` Dale Dellutri
2016-01-02 12:45       ` Simon Clubley
2016-01-02 14:21         ` Britt
2016-01-02 15:29           ` Simon Clubley
2016-01-03  7:11         ` J-P. Rosen
2016-01-03  9:32           ` Simon Wright
2016-01-03  9:59           ` Simon Clubley
2016-01-03 14:23             ` David Botton
2016-01-03 15:48             ` J-P. Rosen
2016-01-03 18:03               ` David Botton
2016-01-03 18:20                 ` Pascal Obry
2016-01-03 19:05                   ` David Botton
2016-01-01 23:50   ` Jeffrey R. Carter
2016-01-02 21:05     ` Bob Duff
2016-01-02 22:53       ` Jeffrey R. Carter
2016-01-02 17:59   ` Dennis Lee Bieber
2016-01-02 18:37     ` Paul Rubin
2016-01-02 21:03       ` Bob Duff
2016-01-02 21:08     ` Bob Duff

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox