comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Funny (so to say...) interaction of "not null" and Vectors?
Date: Tue, 8 Oct 2019 18:21:49 +0200
Date: 2019-10-08T18:21:49+02:00	[thread overview]
Message-ID: <qnid2r$bqp$1@gioia.aioe.org> (raw)
In-Reply-To: 3113a338-c9fd-4c9e-8197-9aca91d2b1d5@googlegroups.com

On 2019-10-08 17:46, mockturtle wrote:

> My suspect is that the dynamically created array can have some null access value, causing the error.
> Does this make any sense?

No it cannot, this is why you get the exception. Logically the default 
initialization of any non-empty array of not null pointers is equivalent 
to raising Constraint_Error.

> If yes, I'll remove the "not null" requirement.

There is a trick to keep "not null" in place. Given you are sure you 
will eventually overwrite all array elements:

    type Target is ...;
    type Pointer is access Target;
    Stock : aliased Target; -- Never ever used anywhere
    type Element is record
       Ptr : not null Pointer := Stock'Access;
    end record;
    type Some_Elements is array (...) of Element;

P.S. Ada needs proper constructors and static checks enforcing these. 
Declarations like of Element must be illegal with checked exception 
contracts.

P.P.S. In the sense that Element requires an initialization, it is an 
unconstrained subtype and should be declared/treated as type

    Element (<>) is ...

That validity cannot be separated from constraint is another problem in Ada.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

  parent reply	other threads:[~2019-10-08 16:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-08 15:46 Funny (so to say...) interaction of "not null" and Vectors? mockturtle
2019-10-08 16:01 ` mockturtle
2019-10-08 16:24   ` J-P. Rosen
2019-10-08 17:38     ` mockturtle
2019-10-09 18:58       ` mockturtle
2019-10-08 16:21 ` Dmitry A. Kazakov [this message]
2019-10-08 17:30   ` mockturtle
replies disabled

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