comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Preventing Unchecked_Deallocation?
Date: Tue, 07 Feb 2012 11:27:52 -0500
Date: 2012-02-07T11:27:52-05:00	[thread overview]
Message-ID: <wcchaz27gmv.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: f4c34323-d0d8-4315-aaaa-31c0119e2ba4@n6g2000vbz.googlegroups.com

Simon Belmont <sbelmont700@gmail.com> writes:

> When you say erroneous, do you mean forbidden by the language (i.e. an
> exception)

No.

>... or that it will cause undefined operation?

Yes.  I suggest you look up the definition of "erroneous"
in the Ada RM.  It doesn't mean what it means in normal English.
I'm planning to write an AdaCore "gem" on this confusing subject
one of these days.

Ada's "erroneous behavior" is roughly equivalent to C's "undefined
behavior".

>...My concern is
> that if a unit exposes an access value to other units, any of them may
> use UD to delete the object at any time.  Obviously this sort of
> behavior would cause the program to quickly crash due to a null
> pointer, ...

That's not obvious!  It might crash slowly.  Worst of all,
it might not crash -- it might do exactly what you wanted,
and now you have a latent bug that might rear it's ugly
head years later.

As others have suggested, the usual solution is to use
a private type.

You could also have a configuration pragma:

    pragma Restrictions(No_Dependence => Ada.Unchecked_Deallocation);

or the GNAT-specific:

    pragma Restriction_Warnings(No_Dependence => Ada.Unchecked_Deallocation);

The latter is more flexible.

- Bob



      parent reply	other threads:[~2012-02-07 16:27 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-02 23:41 Preventing Unchecked_Deallocation? Simon Belmont
2012-02-04 14:40 ` AdaMagica
2012-02-05 16:42   ` Simon Belmont
2012-02-06 12:52     ` Julian Leyh
2012-02-06 16:05       ` Adam Beneschan
2012-02-06 16:21     ` Adam Beneschan
2012-02-06 18:34       ` AdaMagica
2012-02-07  0:14       ` Simon Belmont
2012-02-07  2:19         ` Shark8
2012-02-07 16:39           ` Robert A Duff
2012-02-07 11:42         ` Gautier write-only
2012-02-07 21:11           ` Simon Belmont
2012-02-07 21:30             ` Robert A Duff
2012-02-07 22:23               ` Simon Wright
2012-02-07 23:07                 ` Robert A Duff
2012-02-08  8:43                   ` Simon Wright
2012-02-08 15:06                     ` Robert A Duff
2012-02-09  2:22                     ` Randy Brukardt
2012-02-09  7:28                       ` Simon Wright
2012-02-07 23:06               ` Alan Copeland
2012-02-07 23:10                 ` Robert A Duff
2012-02-09  2:49         ` Randy Brukardt
2012-02-09  3:39           ` Jeffrey Carter
2012-02-09 15:47             ` Adam Beneschan
2012-02-09 19:16               ` Jeffrey Carter
2012-02-09  7:37           ` Simon Wright
2012-02-10  1:08             ` Randy Brukardt
2012-02-10  7:35               ` Simon Wright
2012-02-07  6:26     ` Jeffrey Carter
2012-02-08  8:49       ` Maciej Sobczak
2012-02-08 23:40         ` BrianG
2012-02-09  2:57         ` Randy Brukardt
2012-02-09  7:13           ` Pascal Obry
2012-02-10  1:12             ` Randy Brukardt
2012-02-09  8:08           ` Maciej Sobczak
2012-02-10  1:18             ` Randy Brukardt
2012-02-07 16:27     ` Robert A Duff [this message]
replies disabled

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