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,a79ba897d64210ea,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!newsfeed00.sul.t-online.de!t-online.de!irazu.switch.ch!switch.ch!news.rediris.es!news.um.es!not-for-mail From: "Francisco J. Montoya" Newsgroups: comp.lang.ada Subject: TYPE'Size in static expression Followup-To: comp.lang.ada Date: Fri, 21 Oct 2005 10:04:59 +0200 Organization: Dpto. Informatica y Sistemas (Universidad de Murcia) Message-ID: <4358A12B.4030601@dif.andthis.um.es> NNTP-Posting-Host: montoya.dif.um.es Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: unida.um.es 1129881889 989 155.54.1.41 (21 Oct 2005 08:04:49 GMT) X-Complaints-To: usenet@news.um.es NNTP-Posting-Date: 21 Oct 2005 08:04:49 GMT User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.0.1) Gecko/20020823 Netscape/7.0 X-Accept-Language: es-es, es Xref: g2news1.google.com comp.lang.ada:5845 Date: 2005-10-21T08:04:49+00:00 List-Id: 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