From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,38b27bed88e97415 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-02-20 08:21:43 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!news.tele.dk!news.tele.dk!small.news.tele.dk!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Question: Combination of Access and Constraining Date: Thu, 20 Feb 2003 17:20:45 +0100 Message-ID: References: <1d13e1b4.0302200006.70207b86@posting.google.com> <9d795v0h3qa2922u8vodfhpfvprpre6ak2@4ax.com> <1d13e1b4.0302200720.9666350@posting.google.com> NNTP-Posting-Host: tar-alcarin.cbb-automation.de (212.79.194.111) Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: fu-berlin.de 1045758046 52095034 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:34281 Date: 2003-02-20T17:20:45+01:00 List-Id: 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