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-Thread: 103376,9ce5fb49dc74582f X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!m73g2000cwd.googlegroups.com!not-for-mail From: "Adam Beneschan" Newsgroups: comp.lang.ada Subject: Re: generic question Date: 20 Nov 2006 09:31:17 -0800 Organization: http://groups.google.com Message-ID: <1164043877.922144.53120@m73g2000cwd.googlegroups.com> References: <1163959439.299036.129940@e3g2000cwe.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" X-Trace: posting.google.com 1164043884 29608 127.0.0.1 (20 Nov 2006 17:31:24 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 20 Nov 2006 17:31:24 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: m73g2000cwd.googlegroups.com; posting-host=66.126.103.122; posting-account=cw1zeQwAAABOY2vF_g6V_9cdsyY_wV9w Xref: g2news2.google.com comp.lang.ada:7582 Date: 2006-11-20T09:31:17-08:00 List-Id: markww wrote: > Hi, > > I've been going through ada tutorials, and am looking at the generics > support. I can't quite understand how to accomplish having a record > which has a generic data member. For example, something like: > > type NODE_REC is > record > unknown_data_type : generic; -- not sure how to express > this in ada > Next_Node : NODE_REC_PTR; > Prev_Node : NODE_REC_PTR; > end record; > > I'd like to be able to store either an integer, a float, or some other > user defined record type in there so that this node record becomes a > container. Is this possible? Before we possibly get too far off track, I think we need to know: Are all of the "unknown_data_type" fields in the same container going to have the *same* type? Or are you planning on mixing types---e.g. creating a linked list where some elements in the list have an integer for the unknown_data_type field and some elements in the same list store a float or a user-defined record or something. If it's the second, the generic solutions others have posted won't work. When you declare a generic, you can instantiate it with, say, "integer", "float", or any other type; but then each generic instance will define its own version of NODE_REC and NODE_REC_PTR, and those are *different* types even though they have the same name. Therefore, a NODE_REC_PTR from one generic instance cannot point to a NODE_REC in a different generic instance. If this is what you're trying to do, we'll need a different approach, probably one that will involve tagged types and classwide types. -- Adam