comp.lang.ada
 help / color / mirror / Atom feed
From: "Francisco J. Montoya" <fmontoya.removethis@dif.andthis.um.es>
Subject: TYPE'Size in static expression
Date: Fri, 21 Oct 2005 10:04:59 +0200
Date: 2005-10-21T08:04:49+00:00	[thread overview]
Message-ID: <4358A12B.4030601@dif.andthis.um.es> (raw)

Hello all.

I'm trying to write a generic (container) package whose only parameter 
is a type BaseType. I need to define an array of elements of this type 
(some kind of buffer) but I'd like the size of this buffer to be 
approximately constant regardless of the size of each BaseType element. 
My first attempt was to make some definitions like the following:

  Buffer_Size : constant := 1024; -- 1Kb buffer
  Num_Elements : constant := 8 * Buffer_Size / BaseType'Size; -- Wrong!
  type Buffer is array (1..Num_Elements) of BaseType;

But it's not possible to define Num_Elements this way, since 
BaseType'Size may not appear in a constant expression. I'm interested in 
storing only definite (constrained) types, so I may assume that 
BaseType'Size is a known positive value for any given BaseType. Also, I 
may assume that BaseType'Size <= 8 * Buffer_Size, so the buffer will 
always consist of at least one element.

So far I haven't succeeded in finding a suitable alternative to the 
former (illegal) expression. Of course, I always could add a new (value) 
parameter to the package, and force the instantiation to be like:

   package MyPac is new GenPac (BaseType, BaseType'Size);

but this is something I'd like to avoid as much as possible.

Comments and suggestions are welcome.

Regards,



-- 
Francisco J. Montoya
Depto. Informatica y Sistemas, Facultad de Informatica
(E-30071 Campus de Espinardo) Universidad de Murcia (Spain)
Voice: +34 968 364620, Fax: +34 968 364151,
e-mail: fmontoya AT dif.um.es




             reply	other threads:[~2005-10-21  8:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-21  8:04 Francisco J. Montoya [this message]
2005-10-21  8:55 ` TYPE'Size in static expression Dmitry A. Kazakov
2005-10-21 22:09   ` Jeffrey R. Carter
2005-10-24 10:56   ` Francisco J. Montoya
2005-10-24 11:45     ` Dmitry A. Kazakov
2005-10-24 19:15     ` Jeffrey R. Carter
2005-10-24 20:15       ` Robert A Duff
replies disabled

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