comp.lang.ada
 help / color / mirror / Atom feed
From: Dmitry A. Kazakov <mailbox@dmitry-kazakov.de>
Subject: Re: Question: Combination of Access and Constraining
Date: Thu, 20 Feb 2003 17:20:45 +0100
Date: 2003-02-20T17:20:45+01:00	[thread overview]
Message-ID: <plu95vkp2ttc82k3nsis8bmese5nkj34n0@4ax.com> (raw)
In-Reply-To: 1d13e1b4.0302200720.9666350@posting.google.com

On 20 Feb 2003 07:20:27 -0800, papand0pul0@yahoo.com (Papandopulo)
wrote:

>> Pointers are inherently bad. Why not:
>If they are ingerently bad why they are in
>the language ?

Because there are cases where they have no better alternative.
Nevertheless pointers is a source of countless problems.

>> function Fn (Arg : Tp) return Natural;
>I have to use access type here. Since this is
>simplified example. I have function accepting
>several such array arguments each of which is
>optional (null).

You can overload functions with different profiles.
 
>> But this is another type! Probably you meant a subtype:
>> 
>> subtype TpCon is Tp(1..1);
>Nope, now it says:
>warning: aliased object has explicit bounds.

Right, the above was not for pointers.

>> >So where I am going wrong here ?
>> 
>> You are mixing types and subtypes. If you want just to put a
>> constraint on a type, declare a constrained subtype.
>Gives warnings as I said before: variable with constrained subtype
>can't be aliased (any idea why?).

Because you need bounds to pass with. So if you really want pointers
(instead of letting the compiler to do all the dirty work for you),
then you could go like this:

   type Tp is array (Positive range <>) of Boolean;

   -- This will hold the constraint all the time
   type Tp_Rec (Length : Natural) is record
      Data : Tp (1..Length);
   end record;

   -- This value will serve as a default
   No_Data : aliased Tp_Rec :=
      (Length => 0, Data => (others => False));

    -- Anonymous access is safer
   function Fn (Arg : access Tp_Rec := No_Data'Access) return Natural;

   -- Put a constraint on it
   subtype TpCon is Tp_Rec (1);

   Arr : aliased TpCon; -- This is OK
begin
   Arr.Data (1) := True;
   Res := Fn (Arr'Access);
end Test;

---
Regards,
Dmitry Kazakov
www.dmitry-kazakov.de



  reply	other threads:[~2003-02-20 16:20 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-02-20  8:06 Question: Combination of Access and Constraining Papandopulo
2003-02-20  9:00 ` tmoran
2003-02-20  9:29 ` Dmitry A. Kazakov
2003-02-20 15:20   ` Papandopulo
2003-02-20 16:20     ` Dmitry A. Kazakov [this message]
2003-02-20 17:58     ` Jeffrey Carter
2003-02-20 20:35       ` Yuri
2003-02-21  1:21         ` Jeffrey Carter
2003-02-21 22:53           ` Yuri
2003-02-23 12:34             ` Simon Wright
2003-02-23 17:50               ` Jeffrey Carter
2003-02-23 17:55               ` John R. Strohm
2003-02-23 17:48             ` John R. Strohm
2003-02-20 13:12 ` David C. Hoos, Sr.
2003-02-20 15:00 ` Matthew Heaney
  -- strict thread matches above, loose matches on Subject: below --
2003-02-20  9:46 Grein, Christoph
replies disabled

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