comp.lang.ada
 help / color / mirror / Atom feed
* Re: Ada strangeness or bug in Gnat?
  1996-11-06  0:00 Ada strangeness or bug in Gnat? Henry Ware
@ 1996-11-05  0:00 ` Vincent Celier
  1996-11-06  0:00   ` Joerg Rodemann
                     ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Vincent Celier @ 1996-11-05  0:00 UTC (permalink / raw)



Henry Ware wrote:
> 
> Hi,
> 
> Heres some sample code:

[snip]

>   procedure Sort_Int2 (Unsorted : in Int2_array; Sorted : out Int2_array) is
>       begin
>          if ( Unsorted(1) < Unsorted(2) ) then
>             Sorted(1):=Unsorted(1);
>             Sorted(2):=Unsorted(2);
>          else
>             Sorted(1):=Unsorted(2);
>             Sorted(2):=Unsorted(1);
>          end if;
>       end Sort_Int2;
> 
>    Z: Int2_array;
> 
> begin
>    Z(1):=2;
>    Z(2):=1;
> 
>    -- This should(?) act like a swap
>    Sort_Int2(Z(1..2),Z(1..2));
>    -- ...but actually returns 1,1
>    Put(Z(1));
>    New_Line;
>    Put(Z(2));
>    New_Line;
> end foo3;
> --Cut Here
> 
> The same code works as expected if arrays are not used: ie the
> procedure takes 4 arguments.
> 
> Is this correct?  

The result you are getting is correct (from the point of view of the
compiler). 
Your program is incorrect, because you have a case of a "Bounded Error".

See paragraph 6.2 (12) in RM 95.

The problem is that arrays are passed "by reference", so your two actual
parameters
refer to the same object Z. What you are executing is equivalent to:

   Z(1) := Z(2);
   Z(2) := Z(1);

So, of course, the final result is (1, 1).

Note that your program could work with another compiler that decide to
pass "small"
arrays by copy. But GNAT passes them by reference.

When you use four integers (2 in and 2 out), they are ALWAYS passed by
copy,
because integer types are "elementary types". See 6.2 (3).

No, there is no bug in GNAT (at least here (;-)


> --
> Henry Ware                      hware@cs.wvu.edu

-- Vincent Celier,
-- 9100 McCutcheon Place, RICHMOND, B.C.
-- CANADA, V7A 5A5
-- +1 (604) 241-9811




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

* Re: Ada strangeness or bug in Gnat?
  1996-11-05  0:00 ` Vincent Celier
@ 1996-11-06  0:00   ` Joerg Rodemann
  1996-11-06  0:00     ` Vincent Celier
  1996-11-06  0:00   ` Ronald Cole
  1996-11-07  0:00   ` Peter Amey
  2 siblings, 1 reply; 7+ messages in thread
From: Joerg Rodemann @ 1996-11-06  0:00 UTC (permalink / raw)



Vincent Celier (vcelier@direct.ca) wrote:
> The result you are getting is correct (from the point of view of the
> compiler). 
> Your program is incorrect, because you have a case of a "Bounded Error".

Sure? Soory, but i haven't got my RM at hand right now. But i tried this
sample program with GNAT-3.05 on HPUX 10.10. It says: 1,2. That means the
array elements were swapped --- correctly?

To my understanding the words "in", "out" and "in out" do not seem to make
sense any more for array parameters if your explanation ist correct.
So could someone increase my knowledge?

Quite curious

George

--
Joerg 'George' Rodemann                      Erhard-Groezinger-Strasse 82
Department of Physics                                   D-89134 Blaustein
University of Ulm                                      Tel. (0731) 553319
e-mail:                                    rodemann@mathematik.uni-ulm.de




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

* Re: Ada strangeness or bug in Gnat?
  1996-11-05  0:00 ` Vincent Celier
  1996-11-06  0:00   ` Joerg Rodemann
@ 1996-11-06  0:00   ` Ronald Cole
  1996-11-06  0:00     ` Robert Dewar
  1996-11-07  0:00   ` Peter Amey
  2 siblings, 1 reply; 7+ messages in thread
From: Ronald Cole @ 1996-11-06  0:00 UTC (permalink / raw)



rodemann@mathematik.uni-ulm.de (Joerg Rodemann) writes:
> Sure? Soory, but i haven't got my RM at hand right now. But i tried this
> sample program with GNAT-3.05 on HPUX 10.10. It says: 1,2. That means the
> array elements were swapped --- correctly?

The PA-RISC port of GNAT has some esoteric problems...  (in the
backend, to be more precise)

I wouldn't posit the correctness of my programs on the basis of the
results I get upon running it on this platform.

-- 
Forte International, P.O. Box 1412, Ridgecrest, CA  93556-1412
Ronald Cole <ronald@ridgecrest.ca.us>    Phone: (619) 499-9142
President, CEO                             Fax: (619) 499-9152
My PGP fingerprint: E9 A8 E3 68 61 88 EF 43  56 2B CE 3E E9 8F 3F 2B




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

* Ada strangeness or bug in Gnat?
@ 1996-11-06  0:00 Henry Ware
  1996-11-05  0:00 ` Vincent Celier
  0 siblings, 1 reply; 7+ messages in thread
From: Henry Ware @ 1996-11-06  0:00 UTC (permalink / raw)



Hi,

Heres some sample code:

---Cut Here
with Ada.Text_Io, Ada.Integer_text_io;
use Ada.Text_Io, Ada.Integer_text_io;

procedure foo3 is 
   
   type Int2_Array is array (1..2) of Integer;

   -- Return the same values sorted in ascending order
   procedure Sort_Int2 (Unsorted : in Int2_array; Sorted : out Int2_array) is
      begin
	 if ( Unsorted(1) < Unsorted(2) ) then
	    Sorted(1):=Unsorted(1);
	    Sorted(2):=Unsorted(2);
	 else 
	    Sorted(1):=Unsorted(2);
	    Sorted(2):=Unsorted(1);
	 end if;
      end Sort_Int2;

   Z: Int2_array;
   
begin
   Z(1):=2;
   Z(2):=1;

   -- This should(?) act like a swap 
   Sort_Int2(Z(1..2),Z(1..2));
   -- ...but actually returns 1,1
   Put(Z(1));
   New_Line;
   Put(Z(2));
   New_Line;
end foo3;
--Cut Here

The same code works as expected if arrays are not used: ie the
procedure takes 4 arguments.

Is this correct?  We are using Gnat3.03.

Thanks,
--
Henry Ware			hware@cs.wvu.edu
% rm file
rm: remove file? y
rm: you realize that you'll never get it back? y
rm: wouldn't you rather keep it? n
rm: ok, now let me get this straight.  you voted for clinton last election
    and you want me to trust your judgment on deleting this file.  personally,
    i don't feel you're qualified for a decision of this caliber.  how about
    we run xeyes instead? n
rm: are you absolutely positively sure that you want to remove this file? y
rm: hesitation detected in reply. file not removed.




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

* Re: Ada strangeness or bug in Gnat?
  1996-11-06  0:00   ` Ronald Cole
@ 1996-11-06  0:00     ` Robert Dewar
  0 siblings, 0 replies; 7+ messages in thread
From: Robert Dewar @ 1996-11-06  0:00 UTC (permalink / raw)



Ronald Cole says

"I wouldn't posit the correctness of my programs on the basis of the
results I get upon running it on this platform."

This behavior is not a result of suppsed backend problems in the PA RISC
version of GNAT. We have a number of customers using the HP PA RISC
port of GNAT, and it seems to be in good shape. This is the current
3.07 version, and it is true that this fixes some problems in the
current public release, but these problems show up in quite different
ways than the problem at hand, so Ronald's guess that the behavior
might be due to backend problems is dubious.

We expect the public release of several of the 3.07 versions next week.





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

* Re: Ada strangeness or bug in Gnat?
  1996-11-06  0:00   ` Joerg Rodemann
@ 1996-11-06  0:00     ` Vincent Celier
  0 siblings, 0 replies; 7+ messages in thread
From: Vincent Celier @ 1996-11-06  0:00 UTC (permalink / raw)



Joerg Rodemann wrote:
> 
> Vincent Celier (vcelier@direct.ca) wrote:
> > The result you are getting is correct (from the point of view of the
> > compiler).
> > Your program is incorrect, because you have a case of a "Bounded Error".
> 
> Sure? Soory, but i haven't got my RM at hand right now. But i tried this
> sample program with GNAT-3.05 on HPUX 10.10. It says: 1,2. That means the
> array elements were swapped --- correctly?

It is not because it works with GNAT-3.05 on HPUX 10.10 that the program
is
not at fault: it is still a bounded error. RM95 6.2 (12) says that:
   "The possible consequences are that Program_Error is raised, or the
newly 
    assigned value is read, or some old value of the object is read."

Henry Ware met the second case (newly assigned value) while you met the
third case (old value).

It does not change the fact that it is a bounded error, thus this
program
is not portable.

> To my understanding the words "in", "out" and "in out" do not seem to make
> sense any more for array parameters if your explanation ist correct.
> So could someone increase my knowledge?

If a parameter is passed by copy, then it is read before executing the
subprogram
(for "in" and "in out") and/or updated after executing the subprogram
(for "out"
and "in out") (RM95 6.2 (2)).

If a parameter is passed by reference, "reads and updates of the formal
parameter
directly reference the actual parameter." (RM95 6.2(1))

> Quite curious
> 
> George
> 
> --
> Joerg 'George' Rodemann                      Erhard-Groezinger-Strasse 82
> Department of Physics                                   D-89134 Blaustein
> University of Ulm                                      Tel. (0731) 553319
> e-mail:                                    rodemann@mathematik.uni-ulm.de

-- Vincent Celier,
-- 9100 McCutcheon Place, RICHMOND, B.C.
-- CANADA, V7A 5A5
-- +1 (604) 241-9811




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

* Re: Ada strangeness or bug in Gnat?
  1996-11-05  0:00 ` Vincent Celier
  1996-11-06  0:00   ` Joerg Rodemann
  1996-11-06  0:00   ` Ronald Cole
@ 1996-11-07  0:00   ` Peter Amey
  2 siblings, 0 replies; 7+ messages in thread
From: Peter Amey @ 1996-11-07  0:00 UTC (permalink / raw)



> rodemann@mathematik.uni-ulm.de (Joerg Rodemann) writes:
> > Sure? Soory, but i haven't got my RM at hand right now. But i tried this
> > sample program with GNAT-3.05 on HPUX 10.10. It says: 1,2. That means the
> > array elements were swapped --- correctly?
> 
> The PA-RISC port of GNAT has some esoteric problems...  (in the
> backend, to be more precise)
> 
> I wouldn't posit the correctness of my programs on the basis of the
> results I get upon running it on this platform.
> 

The whole point of the example is that _either_ result is allowed by a
legal compiler which is why the Ada is considered erroneous (to use the
Ada83 term). 

If you must, because of the importance of your software, avoid such
problems entirely then you need to use additional development tools, such
as the SPARK Examiner, which detect all instances of aliasing. 

Peter





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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-11-06  0:00 Ada strangeness or bug in Gnat? Henry Ware
1996-11-05  0:00 ` Vincent Celier
1996-11-06  0:00   ` Joerg Rodemann
1996-11-06  0:00     ` Vincent Celier
1996-11-06  0:00   ` Ronald Cole
1996-11-06  0:00     ` Robert Dewar
1996-11-07  0:00   ` Peter Amey

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