comp.lang.ada
 help / color / mirror / Atom feed
* Which is right here - GNAT or OA ?
@ 1999-05-30  0:00 Vladimir Olensky
  1999-05-30  0:00 ` Robert Dewar
                   ` (3 more replies)
  0 siblings, 4 replies; 57+ messages in thread
From: Vladimir Olensky @ 1999-05-30  0:00 UTC (permalink / raw)


----------------------------------
--  Which is right here - GNAT or OA ?
---------------------------------

Recently I found some time to prepare for "AdaPower" some
"touch and feel" examples (just brushing up my old exercises) on
using controlled types for user defined GB which could be useful
for people learning Ada. It is one of the ways to attract new
people to Ada by explaining very simply some things
that may seem very difficult.

I mentioned about my simple user GB examples few months ago in GB
thread but then I had no time to prepare them for open use.
Then there was nice article about smart pointers by
Mathew Heaney describing the same issue and I did not feel like
adding anything else to this subject.
Then AdaPower come to the  existence (thanks to David Button)
and I felt that it is better late than never.

While working on that examples  I also was preparing some
introductory examples where I tried to put light on some things
that may be unclear to the beginners.

One of these intro examples is the effect of using
Ada.Unchecked_Deallocation for pointers referencing
different types of objects and objects allocated differently.
(one  may have a list of objects that are allocated differently
and he/she wants that the same operations on the items of this list
would have the same effect)

To my surprise I found that GNAT 3.11p and OA (ObjectAda Special
Edition version 7.1.424) give different results for the same test  under
Windows 98.

Here is this example :

------------------------------------------------------
-- Author: Vladimir Olensky, May 1999
--
-- This example shows what happens when you are
-- trying to deallocate static tagged object ( non controlled)
---------------------------------------------------------
with Ada.Unchecked_Deallocation;
with Ada.Text_Io; use Ada.Text_Io;
with Ada.Integer_Text_Io; use Ada.Integer_Text_Io;
procedure Tst_A4 is

   Type Q is record
      ID:Integer:=0;
   end record;

   type Q_A is access all Q;

   procedure Free is new
       Ada.Unchecked_Deallocation(Q,Q_A);

    -- statically declared  object
    q1: aliased Q;
    q_ptr:Q_A;

begin
   q1.ID:=10;
   q_ptr:=q1'Access;

   Put(" Object ID = ");
   Put( (q_ptr.all.ID),2);
   New_Line;
   Put_line("-----------------------------------");

-- Statement_1:
   free(q_ptr);
-------------------
   q1.ID:=20;
   Put(" Object ID = ");

-- Statement_2:
   Put( (q1.ID),2);
-------------------
   New_Line;
   Put(" q_ptr Object ID = ");

-- Statement_3:
   Put( (q_ptr.all.ID),2);
----------------------------------

   New_Line;

end Tst_A4;

*******************************************
In this test we have:

GNAT: - executing statement_1 with no problems.
  after that we have:
  1. q_ptr=null
  2. q1 continue to exists
  As a result GNAT is executing Statement_2 with no problems
  and printing "Object ID = 20" and  then raising
  CONSTRAINT_ERROR exception at Statement_3
  (it should be so as q_ptr=null)

OA:  - raising exception at Statement_1:

For me the right behavior of the Ada.Unchecked_Deallocation for
pointer to statically allocated object (regardless of what RM is
saying now) would be not to try to deallocate static object of any
type - tagged or not tagged, controlled or uncontrolled and assign
null value to pointer for which Ada.Unchecked_Deallocation was invoked.

Why there is no such thing in RM Section 13.11.2 after paragraph 9 ?
Were there any reasons not to describe this case?

To me GNAT behavior is better than OA though is not consistent.
( for controlled types  GNAT behaves differently - it raises
   PROGRAM_ERROR : EXCEPTION_ACCESS_VIOLATION).

RM Section 13.11.2 does not describe clearly and explicitly this case
so there is no wonder that the two best compiles behave differently.

It is interesting if similar test is included in Ada compiles validation
procedures.


It would be interesting to hear comments regarding this issue.

Regards,

Vladimir_Olensky







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

end of thread, other threads:[~1999-06-21  0:00 UTC | newest]

Thread overview: 57+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-05-30  0:00 Which is right here - GNAT or OA ? Vladimir Olensky
1999-05-30  0:00 ` Robert Dewar
1999-05-31  0:00   ` Vladimir Olensky
1999-05-31  0:00     ` Robert Dewar
1999-06-01  0:00   ` dennison
1999-05-30  0:00 ` Florian Weimer
1999-05-31  0:00   ` Vladimir Olensky
1999-05-31  0:00     ` Robert Dewar
1999-06-05  0:00       ` Vladimir Olensky
1999-06-05  0:00         ` Vladimir Olensky
1999-06-05  0:00           ` Robert Dewar
1999-06-07  0:00             ` Ada safety road Was: Which is right Vladimir Olensky
1999-06-06  0:00               ` Larry Kilgallen
1999-06-07  0:00                 ` Keith Thompson
1999-06-07  0:00                   ` Hyman Rosen
1999-06-08  0:00                     ` Robert A Duff
1999-06-08  0:00                       ` Keith Thompson
1999-06-09  0:00                         ` dennison
1999-06-09  0:00                           ` Entamology of "Nasal Demons" dennison
1999-06-09  0:00                         ` Ada safety road Was: Which is right Robert Dewar
1999-06-09  0:00                           ` Tucker Taft
1999-06-09  0:00                             ` Robert Dewar
1999-06-08  0:00                       ` Robert Dewar
1999-06-09  0:00                       ` dennison
1999-06-08  0:00                   ` Robert A Duff
1999-06-08  0:00                   ` Robert Dewar
1999-06-07  0:00                     ` Keith Thompson
1999-06-08  0:00                     ` Robert A Duff
1999-06-14  0:00                   ` Ada safety road Franco Mazzanti
1999-06-15  0:00                     ` Franco Mazzanti
1999-06-16  0:00                       ` Vladimir Olensky
1999-06-06  0:00               ` Ada safety road Was: Which is right Robert Dewar
1999-06-07  0:00                 ` Pascal F. Martin
1999-06-07  0:00                   ` Vladimir Olensky
1999-06-08  0:00                 ` Robert A Duff
1999-06-10  0:00               ` Peter Amey
1999-06-10  0:00                 ` Markus Kuhn
1999-06-11  0:00                   ` Vladimir Olensky
1999-06-12  0:00                     ` Robert Dewar
1999-06-12  0:00                       ` JP Thornley
1999-06-13  0:00                         ` Vladimir Olensky
1999-06-16  0:00                         ` William Dale
1999-06-19  0:00                           ` JP Thornley
1999-06-21  0:00                           ` Robert A Duff
1999-06-13  0:00                       ` Vladimir Olensky
1999-06-12  0:00                         ` Matthew Heaney
1999-06-13  0:00                           ` Vladimir Olensky
1999-06-13  0:00                         ` Robert Dewar
1999-06-13  0:00                           ` Vladimir Olensky
1999-06-13  0:00                           ` swhalen
1999-06-13  0:00                         ` Robert Dewar
1999-06-13  0:00                           ` Vladimir Olensky
1999-06-05  0:00         ` Which is right here - GNAT or OA ? Florian Weimer
1999-06-01  0:00   ` Tucker Taft
1999-05-31  0:00 ` David Botton
1999-06-01  0:00   ` dennison
1999-06-03  0:00 ` Matthew Heaney

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