comp.lang.ada
 help / color / mirror / Atom feed
* Getting modular type size in bits
@ 2003-03-14 15:03 Jano
  2003-03-14 15:41 ` Robert A Duff
  0 siblings, 1 reply; 5+ messages in thread
From: Jano @ 2003-03-14 15:03 UTC (permalink / 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
-------------------------



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-03-14 21:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-14 15:03 Getting modular type size in bits Jano
2003-03-14 15:41 ` Robert A Duff
2003-03-14 15:48   ` Lutz Donnerhacke
2003-03-14 17:20     ` Robert A Duff
2003-03-14 21:05   ` Jano

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