comp.lang.ada
 help / color / mirror / Atom feed
From: Laurent.Guerby@enst-bretagne.fr (Laurent Guerby)
Subject: Re: Free'ing extended types
Date: 1996/04/26
Date: 1996-04-26T00:00:00+00:00	[thread overview]
Message-ID: <4xpw8uirui.fsf@leibniz.enst-bretagne.fr> (raw)
In-Reply-To: 3180F084.7285@ehs.ericsson.se


Jonas Nygren writes
: I read the following in the RM on unchecked_deallocation:
: 
: 13.11.2(16)
:      .... The execution of a call to an instance of 
:      Unchecked_Deallocation is erroneous if the object 
:      was created other than by an allocator for an 
:      access type whose pool is Name'Storage_Pool. 
: 
: I don't quite understand what is written but have a
: vague feeling that the code example below could be
: labeled 'erroneous execution' by the above paragraph.
: 
: Perhaps somebody can answer - is the following code legal:
: 
: type a is tagged with .........;
: type ap is access all a'class;
: 
: procedure free is new unchecked_deallocation(a, ap);
: 
: tybe b is new a with .........; -- a is extended
: 
: p : ap := new b;
: 
: free(p);
: 
: Are 'a' and 'b' belonging to the same Name'Storage_Pool?
: 
: /jonas

   You should ask  your favorite compiler  ;-).  In this case  I don't
think GNAT  is  wrong, and the  error  message is  quite explicit. The
problem is the "all"  in  the access  type  definition, making ap   an
access-to-variable type, see RM95-3.10(10).  Of course if this was not
catched by  some  compile-time   rule, it  would  be    something like
erroneous ;-).

with Ada.Unchecked_Deallocation;
procedure St is

   type a is tagged record X : Integer; end record;
   type ap is access all a'class;

   procedure free is new Ada.unchecked_deallocation(a, ap);

   type b is new a with record
     Y : Integer; end record; -- a is extended

   p : ap := new b;

begin
   free(p);
end St;

guerby@leibniz$ cd ~/ada/tmp/
guerby@leibniz$ gcc -c -gnatvef st.adb
GNAT Compiler Version 3.04w Copyright 1995 Free Software Foundation, Inc.

Compiling: st.adb (source file time stamp: 1996-04-26 21:35:40)

     7.    procedure free is new Ada.unchecked_deallocation(a, ap);
                                                               |
        >>> designated type of actual does not match that of formal "Name"

     7.    procedure free is new Ada.unchecked_deallocation(a, ap);
                                                               |
        >>> instantiation abandoned

    15.    free(p);
           |
        >>> "free" is undefined

 16 lines: 3 errors

Compilation exited abnormally with code 1 at Fri Apr 26 23:35:49

-- 
--  Laurent Guerby, student at Telecom Bretagne (France), Team Ada.
--  "Use the Source, Luke. The Source will be with you, always (GPL)."
--  http://www-eleves.enst-bretagne.fr/~guerby/ (GATO Project).
--  Try GNAT, the GNU Ada 95 compiler (ftp://cs.nyu.edu/pub/gnat).




  reply	other threads:[~1996-04-26  0:00 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-26  0:00 Free'ing extended types Jonas Nygren
1996-04-26  0:00 ` Laurent Guerby [this message]
1996-04-27  0:00   ` Jerry van Dijk
1996-04-28  0:00     ` Robert Dewar
1996-04-28  0:00   ` Jonas Nygren
  -- strict thread matches above, loose matches on Subject: below --
1996-04-28  0:00 Jonas Nygren
1996-04-28  0:00 ` Robert Dewar
1996-04-29  0:00   ` Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00   ` Laurent Guerby
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00   ` Jonas Nygren
1996-04-29  0:00     ` Robert A Duff
1996-04-29  0:00       ` Robert Dewar
1996-04-29  0:00         ` Robert A Duff
1996-04-29  0:00       ` Jonas Nygren
replies disabled

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