comp.lang.ada
 help / color / mirror / Atom feed
From: Sandro Magi <smagi@naasking.homeip.net>
Subject: Discriminant computation problem
Date: Sun, 14 Nov 2004 20:11:10 -0500
Date: 2004-11-14T20:11:10-05:00	[thread overview]
Message-ID: <NmTld.122$rc.97840@news20.bellglobal.com> (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?



             reply	other threads:[~2004-11-15  1:11 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-11-15  1:11 Sandro Magi [this message]
2004-11-15  3:24 ` Discriminant computation problem 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
replies disabled

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