comp.lang.ada
 help / color / mirror / Atom feed
From: "G.B." <bauhaus@notmyhomepage.invalid>
Subject: Re: A function that cannot be called?
Date: Sun, 21 Oct 2018 12:14:03 +0200
Date: 2018-10-21T12:14:03+02:00	[thread overview]
Message-ID: <pqhjhc$5vr$1@dont-email.me> (raw)
In-Reply-To: <d8e778fb-09d0-4989-b1e0-76b3148211f5@googlegroups.com>

On 20.10.18 00:06, Jere wrote:

> Are you ok with runtime checks?  If so, you can create a separate package
> for the void type:
> 
>      package Voids is
>          type Void is limited private;
>      private
>          type Void is new Ada.Finalization.Limited_Controlled
>              with null record;
>          overriding procedure Initialize(Self : in out Void);
>      end Voids;
>      package body Voids is
>          procedure Initialize(Self : in out Void) is
>          begin
>              raise Program_Error;
>          end Initialize;
>      end Voids;
> 
> Here, if try to create a variable of type Void, it will raise
> Program_Error (or you can add a custom exception.  Same for if
> you call a function that tries to return a Voids.Void variable.

I like the idea because the compiler will probably not suppress
raising the exception. This is unlike relying on Constraint_Error
being raised for 1..0. The not null constraint on a component
triggers C_E not matter what, it seems. However, Initialize states
the intention directly.


  reply	other threads:[~2018-10-21 10:14 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-18 12:14 A function that cannot be called? G.B.
2018-10-18 15:33 ` Stefan.Lucks
2018-10-18 20:21   ` G.B.
2018-10-18 20:57     ` Niklas Holsti
2018-10-19  7:15     ` Dmitry A. Kazakov
2018-10-19 13:55       ` G.B.
2018-10-19 15:31         ` Dmitry A. Kazakov
2018-10-18 17:03 ` AdaMagica
2018-10-18 19:36   ` G.B.
2018-10-18 21:30     ` Randy Brukardt
2018-10-19 14:00       ` G.B.
2018-10-19 15:39         ` Dmitry A. Kazakov
2018-10-20  1:34         ` Randy Brukardt
2018-10-20  9:14           ` G.B.
2018-10-20 11:13             ` Simon Wright
2018-10-20 14:11               ` Dmitry A. Kazakov
2018-10-21  9:25                 ` G.B.
2018-10-21  9:07               ` G.B.
2018-10-21  9:51                 ` Dmitry A. Kazakov
2018-10-21 10:57                 ` Niklas Holsti
2018-10-21 18:00                 ` Simon Wright
2018-10-19  8:48 ` AdaMagica
2018-10-19 11:15   ` G.B.
2018-10-19 17:06     ` AdaMagica
2018-10-19 19:57       ` G.B.
2018-10-19 22:06         ` Jere
2018-10-21 10:14           ` G.B. [this message]
2018-10-21 11:30             ` Egil H H
2018-10-23 11:45               ` G.B.
2018-10-23 14:35                 ` Jere
2018-10-23 14:57                   ` Dmitry A. Kazakov
2018-10-23 17:49                     ` G.B.
2018-10-23 19:25                       ` Dmitry A. Kazakov
2018-10-24  7:35                         ` G.B.
2018-10-24  8:14                           ` Dmitry A. Kazakov
2018-10-19 18:19 ` marciant
2018-10-19 18:22   ` marciant
2018-10-20  1:36     ` Randy Brukardt
2018-10-20  2:54       ` marciant
2018-10-19 20:25   ` Shark8
2018-10-19 23:28     ` marciant
replies disabled

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