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,cea03ed275aa3d28,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!198.186.190.247.MISMATCH!news-out.readnews.com!news-xxxfer.readnews.com!not-for-mail Newsgroups: comp.lang.ada Subject: Question about generics. From: "Peter C. Chapin" Organization: Kelsey Mountain Software Message-ID: User-Agent: Xnews/5.04.25 Date: 02 Jul 2006 16:08:42 GMT NNTP-Posting-Host: 2026f847.news.sover.net X-Trace: DXC=@L1bV^5UaTW?f1gG?hTK6_LM2JZB_ShA^mA3hQcaV3?@`i3kGa5[o\ZEhfQeHEWLoi>7_F6GWU X-Complaints-To: abuse@sover.net Xref: g2news2.google.com comp.lang.ada:5415 Date: 2006-07-02T16:08:42+00:00 List-Id: Here is what I'm trying to do generic Size : in Integer; package Xyzzy is type Index is mod Size; -- etc. end Xyzzy; The compiler (gnat) complains about the modular type definition, saying that Size is a non-static expression and that's no good. I understand what this error means and I understand the rationale behind it (thanks to looking in Cohen's book "Ada As a Second Language"). My question is: how can I get the effect I'm looking for? My plan is to only instantiate the package with constants so all the necessary information should be available at compile time. For example package Fizzle is new Xyzzy(Size => 10); I realize that I could make the Index type a generic parameter but that would require me to define the type at the point of instantiation and that seems unnatural. Conceptually I'm trying to parameterize the package on a (static) size. It doesn't seem like I should have to define a type to express that concept. I admit that I'm a C++ programmer and I'm used to using non-type parameters in templates to obtain this effect. template< int size > class Xyzzy { char array[size]; // size is a compile time constant. }; Peter