comp.lang.ada
 help / color / mirror / Atom feed
From: Jano <402450@cepsz.unizar.es>
Subject: Getting modular type size in bits
Date: Fri, 14 Mar 2003 16:03:07 +0100
Date: 2003-03-14T16:03:07+01:00	[thread overview]
Message-ID: <MPG.18dc0d98f36ac6bb9896b9@News.CIS.DFN.DE> (raw)

Hello,

maybe I'm overlooking something really silly:

I have a generic function, for example:

generic
   type Number is Mod <>;
function Do(X: Number) return Number;

I need to perform operations based on the logical type size, i.e.
if the type is

type Number is Mod 2**32;

I want to know that the type size is 5. I'm aware of the 'modulus 
attribute, and 'size. If I understand correctly, 'size returns the size 
allocated by the compiler for the type (normally 8 in this case), not 
the _minimum_ size to allocate it (which is what I would need in that 
case).

I can think of performing a log2 op, or some iterative proc to find it, 
but I would know if there is some ultra-efficient method (because the 
compiler has to know, I suppose, that size), because that function could 
be potentially called many times in loops.

If I were using a generic package, I could perform that calculus in 
elaboration time, but is a generic function and I'd like to maintain it 
like that if possible. Other possibility but I can't think a mean of 
doing it would be a static expression who evaluates to that value, place 
it in the declarative part of the function, and hope that it will not be 
re-evaluated in each call... I don't know if it works that way.

I'm getting off course? Can you point me in the right direction?

Many thanks,

-- 
-------------------------
Jano
402450[at]cepsz.unizar.es
-------------------------



             reply	other threads:[~2003-03-14 15:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-03-14 15:03 Jano [this message]
2003-03-14 15:41 ` Getting modular type size in bits Robert A Duff
2003-03-14 15:48   ` Lutz Donnerhacke
2003-03-14 17:20     ` Robert A Duff
2003-03-14 21:05   ` Jano
replies disabled

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