comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: New to Ada, why these warning messages?
Date: Fri, 01 Jan 2016 12:30:38 -0500
Date: 2016-01-01T12:30:38-05:00	[thread overview]
Message-ID: <5fbd8blmdrlb9cpnjrj20edcttm8m0e68v@4ax.com> (raw)
In-Reply-To: n64nnt$ft6$1@reader1.panix.com

On Fri, 1 Jan 2016 02:19:41 +0000 (UTC), Dale Dellutri
<daQQQle@panQQQix.com> declaimed the following:

>   PNames: array(Paint) of String(1..6) :=
>     ("Red   ", "Green ", "Yellow", "Blue  ", "Pink  ", "Orange", 
>"Mauve ",
>      "Cherry", "Indigo", "Brown ");
>

	Why?


>   for I in 1..N loop

	Ada FOR loop index variables are automatically declared and typed to
match the range provided. Which, as others have mentioned, should really be
defined as the 'range of the type, not some magic numbers.

	And that IS what the error messages were telling you...

>gnatarr2.adb:54:08: warning: for loop implicitly declares loop 
>variable
>gnatarr2.adb:54:08: warning: declaration hides "I" declared at line 24

>      Put(PNames(A(I)) & " ");

	Without actually coding it, I'd think this could be replaced by

	put(Paint'Image(A(i)) & " ");

meaning no need for the additional pnames array.


Okay...  'Image needs work for the alignment
C:\Users\Wulfraed\Ada\GnatArr
  1      2      3      4      5      6      7      8    
RED RED PINK BLUE ORANGE CHERRY INDIGO INDIGO 
BROWN ORANGE BROWN BROWN GREEN INDIGO INDIGO INDIGO 
BLUE BLUE BLUE BLUE BLUE BLUE BLUE BLUE 

[2016-01-01 12:24:35] process terminated successfully, elapsed time: 00.18s

with GNAT.IO; use GNAT.IO;
procedure Gnatarr 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);

   -- 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;

begin

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

   -- Set the entire array to Blue.
   C := (others => Blue);

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

   -- Print out the contents of each of A, B, and C.
   for I in AType'Range loop
      Put (Paint'Image (A (I)) & " ");
   end loop;
   New_Line;

   for I in AType'Range loop
      Put (Paint'Image (B (I)) & " ");
   end loop;
   New_Line;

   for I in AType'Range loop
      Put (Paint'Image (C (I)) & " ");
   end loop;
   New_Line;
end Gnatarr;
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

  parent reply	other threads:[~2016-01-01 17:30 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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
replies disabled

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