comp.lang.ada
 help / color / mirror / Atom feed
* Discriminant computation problem
@ 2004-11-15  1:11 Sandro Magi
  2004-11-15  3:24 ` Jim Rogers
  2004-11-15 22:11 ` Nick Roberts
  0 siblings, 2 replies; 9+ messages in thread
From: Sandro Magi @ 2004-11-15  1:11 UTC (permalink / raw)


Just learning Ada and I came across this little issue. I can't perform a
computation on a discriminant. Suppose I want to create a bit vector type
that uses an array of Integers as its underlying storage type (just an
example). I want the user to provide the length of the bit vector in bits,
but I need to define the upper bound on the Integer array in Integer'Size
units.

type Int_Array is array (Positive range <>) of Integer;

type Bit_Vector (Max_Bit_Size : Positive) is
record
 Series : Int_Array (Positive'First .. Max_Bit_Size/Integer'Size);
end record;

The compiler error gnat produces: "discriminant in constraint must appear
alone". Is there something I'm doing wrong, or is the above simply not
possible?

I can solve this either by breaking the encapsulation of my type so that the
user must perform the computation ahead of time (not preferable), or by
creating a special function which computes the real upper bound. So the
user would have to instantiate:

bv : Bit_Vector(Real_Upper_Bound(1024)); --1024 bits

Instead of:

bv : Bit_Vector(1024); --1024 bits

Does anyone have a better answer?



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

end of thread, other threads:[~2004-11-16 20:14 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-15  1:11 Discriminant computation problem Sandro Magi
2004-11-15  3:24 ` Jim Rogers
2004-11-15 14:02   ` Sandro Magi
2004-11-15 15:16     ` Martin Krischik
2004-11-15 16:02     ` Dmitry A. Kazakov
2004-11-15 22:11 ` Nick Roberts
2004-11-15 23:25   ` tmoran
2004-11-16 20:00     ` Nick Roberts
2004-11-16 20:14       ` tmoran

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