comp.lang.ada
 help / color / mirror / Atom feed
From: "Peter C. Chapin" <pchapin@sover.net>
Subject: Question about generics.
Date: 02 Jul 2006 16:08:42 GMT
Date: 2006-07-02T16:08:42+00:00	[thread overview]
Message-ID: <Xns97F47B960CF95pchapinsovernet@198.186.192.137> (raw)

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



             reply	other threads:[~2006-07-02 16:08 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-07-02 16:08 Peter C. Chapin [this message]
2006-07-02 18:49 ` Question about generics Martin Krischik
2006-07-03  6:30 ` Jeffrey R. Carter
2006-07-03 10:33   ` Peter C. Chapin
2006-07-03 11:42     ` Jean-Pierre Rosen
2006-07-03 16:44     ` Pascal Obry
2006-07-04  1:09       ` Peter C. Chapin
2006-07-04  6:17         ` M E Leypold
2006-07-04 10:48           ` Peter C. Chapin
2006-07-03 20:03     ` Jeffrey R. Carter
2006-07-03 20:18       ` Dmitry A. Kazakov
2006-07-04  0:08         ` Randy Brukardt
2006-07-04  7:48           ` Dmitry A. Kazakov
2006-07-04  0:43         ` Jeffrey R. Carter
2006-07-03  9:46 ` Martin Krischik
2006-07-04 13:29 ` Stephen Leake
2006-07-05 12:08   ` Dmitry A. Kazakov
  -- strict thread matches above, loose matches on Subject: below --
1993-09-02 17:45 question " Stef  Van Vlierberghe
1993-08-12 15:18 Robert I. Eachus
1993-08-11 18:48 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!howland.
1993-08-11  0:25 agate!howland.reston.ans.net!europa.eng.gtefsd.com!darwin.sura.net!seas.g
1993-08-10 15:53 Robert I. Eachus
1993-08-09 21:29 Kenneth Anderson
1989-05-29 20:54 Question " "14827_DAVID PAPAY"
1989-05-29  7:02 "Jonathan B. Owen"
replies disabled

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