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,1116ece181be1aea X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-10-08 00:27:06 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!fu-berlin.de!uni-berlin.de!tar-alcarin.cbb-automation.DE!not-for-mail From: Dmitry A. Kazakov Newsgroups: comp.lang.ada Subject: Re: Counter-proposal for variable arrays Date: Wed, 08 Oct 2003 09:36:29 +0200 Message-ID: <4pe7ov0gsepk8p8cq88ropvq4sookdhatk@4ax.com> References: <3F7B1076.8060106@comcast.net> <5mknnv4u96qqudrt4bd8n4t1cljp2fjlp8@4ax.com> <1065215180.95094@master.nyc.kbcfp.com> <19p2ovk1jh4krn2h5cql44p37ovf6va99i@4ax.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: news.uni-berlin.de 1065598025 17852594 212.79.194.111 (16 [77047]) X-Newsreader: Forte Agent 1.8/32.548 Xref: archiver1.google.com comp.lang.ada:444 Date: 2003-10-08T09:36:29+02:00 List-Id: On Wed, 08 Oct 2003 06:56:37 GMT, Hyman Rosen wrote: >Dmitry A. Kazakov wrote: >> Mmm I guess array is something that one can pass as a parameter. For >> example: >> void Erase (char X [20]) >> { >> memset (X, 0, sizeof (X)); // How many element will be set? >> } > >For C compatibility, C++ arrays have the same decay-to-pointer >semantics in many circumstances. Yep, it has no arrays for compatibility reasons. (:-)) >>>Yeah. So what? What exactly would the implementation of an array of >>>class-wide elements look like, anyway? >> >> Children_And_Pop_Up_Array : >> Container >> ( 1..20, -- Constrain the bounds >> From => Child_Window'Tag, -- Constrain the elements >> To => Pop_Up_Window'Tag >> ); >> >> The array contains 20 elements of types between Child_Window and >> Pop_Up_Window. Note that because all possible types are known, the >> upper bound of the element size is also known. So the array could be >> allocated as usual. > >This seems like a pretty specialized usage to me, not particularly >worthy of dedicated language support. For one thing, classwide types >are there to support object-oriented programming, where you don't >know at the declaration point what types will be used. Exactly. Therefore, please recall my example. The type Container is the type which knows *nothing* about the types it will contain. This is why it is unconstrained. Compare it with the type String, it also does not know how many characters will be there. Only when you create a concrete instance of the type, an object, you have to constrain it, i.e. to say which types are allowed there or how many characters it will hold. This is the whole idea. Observe that it is the same idea as in the case ot generic containers, a pretty specialized usage, you'd say. A "generic type" is also unconstrained, because its actual parameters are unknown. When you instantiate it, you constrain it by providing the parameters. It is exactly the same thing (called generic programming). The difference, though is that with a discriminants instantiation is much more simplier and can be done at run-time. >For your purpose above, can't you just use an array of variant records >instead? Of course not. Variant records have to be explicity specified each time you need an instance of the type. It is same as to propose variant records instead of the type String: type Awful_String (Length : Positive) is record case (Length) is when 1 => One_Char : String (1..1); when 2 => Two_Chars : String (1..2); ... --- Regards, Dmitry Kazakov www.dmitry-kazakov.de