comp.lang.ada
 help / color / mirror / Atom feed
* GNAT for loop can't count!
@ 1997-07-28  0:00 William Paul Berriss
  1997-07-28  0:00 ` Matthew Heaney
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: William Paul Berriss @ 1997-07-28  0:00 UTC (permalink / raw)



Hi

I use GNAT Ada95 compiler v3.07 on a Sun SPARC 5 runnig Solaris 2.5.

I have  very simple for loop that should count upwards from 118 to 129
but it counts 118, ..., 126, 127, -128, -127  (i.e. changes to
Negative after 127)

Here is the loop:

      for P in Pixel(Firstp)..Pixel(Lastp) loop             

        Ada.Integer_Text_IO.Put(Integer(P));
        Ada.Text_IO.New_line;

      end loop;

Where  Pixel is Integer range 0..255
and
Firstp and Lastp at this point are 118 and 129 respectively.
Both of type Pixel.

Very weird!

Any advice or helpful ideas most welcome indeed!!!!!!

Will Berriss
------------

-- 

W P Berriss                 E-mail: W.P.Berriss@reading.ac.uk
Department of Engineering
The University of Reading
Whiteknights
Reading                     Tel:  0118 987 5123 
Berkshire                     (+44 118 987 5123 outside UK)
RG6 6AY    
England                     Fax:  0118 931 3327    

World Wide Web Home Page: 

http://www.elec.rdg.ac.uk/people/postgrads/will.html




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

* Re: GNAT for loop can't count!
  1997-07-28  0:00 GNAT for loop can't count! William Paul Berriss
@ 1997-07-28  0:00 ` Matthew Heaney
  1997-07-28  0:00 ` Robert Dewar
  1997-07-29  0:00 ` Anonymous
  2 siblings, 0 replies; 4+ messages in thread
From: Matthew Heaney @ 1997-07-28  0:00 UTC (permalink / raw)



In article <33DCBE03.27E8@reading.ac.uk>, William Paul Berriss
<W.P.Berriss@reading.ac.uk> wrote:


>I use GNAT Ada95 compiler v3.07 on a Sun SPARC 5 runnig Solaris 2.5.

This is a very old version of GNAT; the current public release is 3.09. 
Have you considered upgrading?

Also, there is a discussion list for GNAT specificially, called
<mailto:chat@gnat.com>.  Go to the ACT website at <http://www.gnat.com> to
get info about signing up, and consider posting GNAT-specific queries
there.


>I have  very simple for loop that should count upwards from 118 to 129
>but it counts 118, ..., 126, 127, -128, -127  (i.e. changes to
>Negative after 127)
>
>Here is the loop:
>
>      for P in Pixel(Firstp)..Pixel(Lastp) loop             
>
>        Ada.Integer_Text_IO.Put(Integer(P));
>        Ada.Text_IO.New_line;
>
>      end loop;
>
>Where  Pixel is Integer range 0..255
>and
>Firstp and Lastp at this point are 118 and 129 respectively.
>Both of type Pixel.

What is type Pixal? Is it 

   subtype Pixal is Integer range 0 .. 255;

If so, then why did you declare your loop as you did?  Why the cast to
Pixal type, if Firstp and Lastp are already type Pixal?  Why not

   for P in Pixal range Firstp .. Lastp loop

Also, why did you cast the loop index to type integer, if Pixal is already
a subtype of Integer?  Why not

   Ada.Integer_Text_IO.Put (P);

It would help if you showed the _exact_ declaration of type Pixal.

--------------------------------------------------------------------
Matthew Heaney
Software Development Consultant
<mailto:matthew_heaney@acm.org>
(818) 985-1271




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

* Re: GNAT for loop can't count!
  1997-07-28  0:00 GNAT for loop can't count! William Paul Berriss
  1997-07-28  0:00 ` Matthew Heaney
@ 1997-07-28  0:00 ` Robert Dewar
  1997-07-29  0:00 ` Anonymous
  2 siblings, 0 replies; 4+ messages in thread
From: Robert Dewar @ 1997-07-28  0:00 UTC (permalink / raw)



William Berris says

<<I use GNAT Ada95 compiler v3.07 on a Sun SPARC 5 runnig Solaris 2.5.>>

This is quite a bit out of date by now, 3.09 was publicly released quite
a while ago, I suggest updating to this version. If you *do* think you
have discovered a bug, please follow the directions in the documentation
and submit a bug report.





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

* Re: GNAT for loop can't count!
  1997-07-28  0:00 GNAT for loop can't count! William Paul Berriss
  1997-07-28  0:00 ` Matthew Heaney
  1997-07-28  0:00 ` Robert Dewar
@ 1997-07-29  0:00 ` Anonymous
  2 siblings, 0 replies; 4+ messages in thread
From: Anonymous @ 1997-07-29  0:00 UTC (permalink / raw)



On Mon, 28 Jul 1997 16:42:59 +0100, William Paul Berriss
<W.P.Berriss@reading.ac.uk> wrote:

>       for P in Pixel(Firstp)..Pixel(Lastp) loop             
> 
>         Ada.Integer_Text_IO.Put(Integer(P));
>         Ada.Text_IO.New_line;
> 
>       end loop;
> 
> Where  Pixel is Integer range 0..255
> and
> Firstp and Lastp at this point are 118 and 129 respectively.
> Both of type Pixel.

GNAT 3.07/Solaris/Sparc:

with Ada.Text_Io;

use Ada;
procedure Junk is
   subtype Pixel is Integer range 0 .. 255;

   Firstp : Pixel;
   Lastp  : Pixel;
begin -- Junk
   Firstp := 118;
   Lastp  := 129;

   Text_Io.Put_Line (Pixel'Image (Firstp) & Pixel'Image (Lastp) );

   for P in Pixel (Firstp) .. Pixel (Lastp) loop
      Text_IO.Put_Line (Integer'Image (Integer (P) ) );
   end loop;

   Text_Io.Skip_Line;

   for P in Firstp .. Lastp loop
      Text_Io.Put_Line (Pixel'Image (P) );
   end loop;
end Junk;

Output:

 118 129
 118
 119
 120
 121
 122
 124
 125
 126
 127
 129

 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129


Jeff Carter  PGP:1024/440FBE21
My real e-mail address: ( carter @ innocon . com )
"Now go away or I shall taunt you a second time."
Monty Python & the Holy Grail

Posted with Spam Hater - see
http://www.compulink.co.uk/~net-services/spam/




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

end of thread, other threads:[~1997-07-29  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-07-28  0:00 GNAT for loop can't count! William Paul Berriss
1997-07-28  0:00 ` Matthew Heaney
1997-07-28  0:00 ` Robert Dewar
1997-07-29  0:00 ` Anonymous

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