comp.lang.ada
 help / color / mirror / Atom feed
From: Nick Roberts <nickroberts@blueyonder.co.uk>
Subject: Re: Unchecked_Deallocation subtleties
Date: Wed, 09 Apr 2003 21:19:06 +0100
Date: 2003-04-09T21:19:06+01:00	[thread overview]
Message-ID: <oprndpd4lebqmqul@news.cis.dfn.de> (raw)
In-Reply-To: <3E94502E.6070108@cogeco.ca>

On Wed, 09 Apr 2003 12:54:06 -0400, Warren W. Gay VE3WWG <ve3wwg@cogeco.ca> 
wrote:

[that an instance of Unchecked_Deallocation (e.g. 'Free') permits
the access value passed to it to be null]
>
> I have always believed that this type of "permissiveness" is
> bad. If the caller knew in advance that there was nothing to
> free, then Free(X) would never be called in the first place.
> To me, this (when X is null) should raise an exception since
> it represents an unintended operation or state of the access
> type [value?].
>
> It appears that a concession has been made to lazy
> programmers so that they can avoid the necessary if
> statements, such as:
>
> if X /= null then
> Free(X);
> end if;

To be fair to the designers of Ada (83), I suspect that upon deep 
deliberation they found that the behaviour specified (a null value is 
permitted, and does nothing) could not sensibly be avoided. I'll try to 
explain why.

Consider the following example skeleton piece of code:

   declare
      X: Some_Access_Type;
   begin
      ...         -- [1]
      Y := X.all; -- [2] last use of X
      ...         -- [3]
      Free(X);    -- [4]
   end;

Although it may be that no compiler would (or even could) do so in 
practice, other rules in the ARM made it theoretically possible for the 
implementation to automatically reclaim the storage occupied by whatever X 
pointed to (assuming no other access value pointed to it) at any point in 
the elided code section [3]. If this were to occur, the implementation 
would be within its rights to set X to null at the same time. Thus X could 
legitimately be null by the time it gets to [4]. In practice this would be 
found to be a general situation.

So, not permitting Free to simply ignore a null value would theoretically 
have condemned every and any call to Free to have the explicit test for a 
null value, and I'm sure that the Ada ('Green') design team didn't fancy 
that idea.

-- 
Nick Roberts
Jabber: debater@charente.de [ICQ: 159718630]



  reply	other threads:[~2003-04-09 20:19 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-09  9:10 Unchecked_Deallocation subtleties Piotr Zgorecki
2003-04-09  9:46 ` Samuel Tardieu
2003-04-09 12:19   ` Marin David Condic
2003-04-09 12:37     ` Samuel Tardieu
2003-04-10 12:02       ` Marin David Condic
2003-04-09 16:54     ` Warren W. Gay VE3WWG
2003-04-09 20:19       ` Nick Roberts [this message]
2003-04-09 21:39         ` Samuel Tardieu
2003-04-10 11:37           ` Nick Roberts
2003-04-10 14:39             ` Robert Spooner
2003-04-10 16:39             ` Warren W. Gay VE3WWG
2003-04-09 19:50 ` Nick Roberts
2003-04-10 15:04   ` Nick Roberts
2003-04-10 16:40     ` chris.danx
2003-04-14 23:42   ` Keith Thompson
2003-04-15  1:54     ` Nick Roberts
2003-04-15 12:00     ` Larry Kilgallen
2003-04-15 12:13       ` Jacob Sparre Andersen
2003-04-19  8:57         ` AG
2003-04-09 21:23 ` Randy Brukardt
2003-04-10 11:49   ` Nick Roberts
replies disabled

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